Skip to content

Commit 5055259

Browse files
author
Ran Yitzhaki
committed
+setMaxTimeout() method to the api
1 parent a9188c9 commit 5055259

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const udpSocket = require('dgram').createSocket('udp4');
4343
const server = udpIO(udpSocket);
4444

4545
server.bind(33334);
46-
46+
server.setMaxTimeout(4000);
4747
server.send('MY_AWESOME_EVENT', { question: 'how are you ?' }, 33335).then((res) => {
4848
console.log(`answer: ${res.answer}`);
4949
});
@@ -61,5 +61,8 @@ server.send('MY_AWESOME_EVENT', { question: 'how are you ?' }, 33335).then((res)
6161
send an event to a certain host, returns an es6 Promise.
6262
`eventName` is a string and `host` is default to localhost.
6363

64+
#### server.setMaxTimeout(milliseconds)
65+
change the max timeout for a request,
66+
which after that the request expires.
6467
## License
6568
MIT

src/udp-io.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = function() {
77
const server = dgram.createSocket('udp4');
88
const pongCbs = {};
99
const pingCbs = {};
10+
let maxTimeout = 5000;
1011

1112
server.on('message', function(response, rinfo) {
1213
const parsedRes = JSON.parse(response.toString());
@@ -46,6 +47,10 @@ module.exports = function() {
4647
server.bind(port, host);
4748
},
4849

50+
setMaxTimeout: function(milliseconds) {
51+
maxTimeout = milliseconds;
52+
},
53+
4954
send: function(eventType, msg, port, host) {
5055
host = host || '127.0.0.1';
5156

@@ -68,7 +73,7 @@ module.exports = function() {
6873

6974
setTimeout(function () {
7075
delete pongCbs[id];
71-
}, 5000);
76+
}, maxTimeout);
7277
});
7378
},
7479

0 commit comments

Comments
 (0)