Skip to content

Commit 0756bd0

Browse files
authored
Merge pull request #101 from hchho/timeout-fix
Fixed uncaught timeout error
2 parents 435e81c + 8afa319 commit 0756bd0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ SSDP.prototype._start = function (cb) {
254254
} catch (e) {
255255
if (e.code === 'ENODEV' || e.code === 'EADDRNOTAVAIL') {
256256
self._logger('Interface %s is not present to add multicast group membership. Scheduling a retry. Error: %s', addr, e.message)
257-
setTimeout(addMembership, 5000)
257+
delay().then(addMembership).catch(e => { throw e })
258258
} else {
259259
throw e
260260
}
@@ -264,6 +264,12 @@ SSDP.prototype._start = function (cb) {
264264
socket.addMembership(self._ssdpIp, iface) // TODO: specifying the interface in there might make a difference
265265
socket.setMulticastTTL(self._ssdpTtl)
266266
}
267+
268+
function delay() {
269+
return new Promise((resolve) => {
270+
setTimeout(resolve, 5000);
271+
});
272+
}
267273
})
268274

269275
if (self._explicitSocketBind) {

0 commit comments

Comments
 (0)