From dcef48903c9fa6e7ece6f42df266c7e752f32b58 Mon Sep 17 00:00:00 2001 From: Devin Samarin Date: Fri, 11 Aug 2017 17:28:38 -0700 Subject: [PATCH] Use node.js timers explicitly to support Electron --- lib/registry.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/registry.js b/lib/registry.js index 04e57d7..ea9a681 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -1,5 +1,6 @@ 'use strict' +var timers = require('timers') var dnsEqual = require('dns-equal') var flatten = require('array-flatten') var Service = require('./service') @@ -81,7 +82,7 @@ function probe (mdns, service, cb) { var timer mdns.on('response', onresponse) - setTimeout(send, Math.random() * 250) + timers.setTimeout(send, Math.random() * 250) function send () { // abort if the service have or is being stopped in the meantime @@ -91,7 +92,7 @@ function probe (mdns, service, cb) { // This function will optionally be called with an error object. We'll // just silently ignore it and retry as we normally would sent = true - timer = setTimeout(++retries < 3 ? send : done, 250) + timer = timers.setTimeout(++retries < 3 ? send : done, 250) timer.unref() }) } @@ -146,7 +147,7 @@ function announce (server, service) { } delay = delay * REANNOUNCE_FACTOR if (delay < REANNOUNCE_MAX_MS && !service._destroyed) { - setTimeout(broadcast, delay).unref() + timers.setTimeout(broadcast, delay).unref() } }) })()