From 2a828292b8522eec300181058f3e3f799bf146ac Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 29 Oct 2020 10:25:57 -1000 Subject: [PATCH] standard --- lib/client/http-tracker.js | 4 +++- lib/client/udp-tracker.js | 4 +++- lib/client/websocket-tracker.js | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/client/http-tracker.js b/lib/client/http-tracker.js index 65dafb0..f611a9e 100644 --- a/lib/client/http-tracker.js +++ b/lib/client/http-tracker.js @@ -81,12 +81,14 @@ class HTTPTracker extends Tracker { this.destroyed = true clearInterval(this.interval) + let timeout + // If there are no pending requests, destroy immediately. if (this.cleanupFns.length === 0) return destroyCleanup() // Otherwise, wait a short time for pending requests to complete, then force // destroy them. - let timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT) + timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT) // But, if all pending requests complete before the timeout fires, do cleanup // right away. diff --git a/lib/client/udp-tracker.js b/lib/client/udp-tracker.js index e2f0c24..0f4c0e4 100644 --- a/lib/client/udp-tracker.js +++ b/lib/client/udp-tracker.js @@ -41,12 +41,14 @@ class UDPTracker extends Tracker { this.destroyed = true clearInterval(this.interval) + let timeout + // If there are no pending requests, destroy immediately. if (this.cleanupFns.length === 0) return destroyCleanup() // Otherwise, wait a short time for pending requests to complete, then force // destroy them. - let timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT) + timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT) // But, if all pending requests complete before the timeout fires, do cleanup // right away. diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index e64503d..907b5d3 100644 --- a/lib/client/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -129,12 +129,14 @@ class WebSocketTracker extends Tracker { socket.on('error', noop) // ignore all future errors socket.once('close', cb) + let timeout + // If there is no data response expected, destroy immediately. if (!this.expectingResponse) return destroyCleanup() // Otherwise, wait a short time for potential responses to come in from the // server, then force close the socket. - let timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT) + timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT) // But, if a response comes from the server before the timeout fires, do cleanup // right away.