From 6df64ffe06aed0bdec70cd613a47e5d092510146 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 14 Mar 2016 19:16:00 -0700 Subject: [PATCH] Fixes for PR #126 --- lib/client/http-tracker.js | 2 +- lib/client/udp-tracker.js | 2 +- lib/client/websocket-tracker.js | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/client/http-tracker.js b/lib/client/http-tracker.js index ec10cc4..282c60a 100644 --- a/lib/client/http-tracker.js +++ b/lib/client/http-tracker.js @@ -74,7 +74,7 @@ HTTPTracker.prototype.scrape = function (opts) { HTTPTracker.prototype.destroy = function (cb) { var self = this - if (self.destroyed) return cb && cb() + if (self.destroyed) return cb(null) self.destroyed = true clearInterval(self.interval) diff --git a/lib/client/udp-tracker.js b/lib/client/udp-tracker.js index 8aec7e1..07d6c35 100644 --- a/lib/client/udp-tracker.js +++ b/lib/client/udp-tracker.js @@ -47,7 +47,7 @@ UDPTracker.prototype.scrape = function (opts) { UDPTracker.prototype.destroy = function (cb) { var self = this - if (self.destroyed) return cb && cb() + if (self.destroyed) return cb(null) self.destroyed = true clearInterval(self.interval) diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index df73062..d85a5ba 100644 --- a/lib/client/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -64,9 +64,10 @@ WebSocketTracker.prototype.scrape = function (opts) { self._onSocketError(new Error('scrape not supported ' + self.announceUrl)) } -WebSocketTracker.prototype.destroy = function (onclose) { +WebSocketTracker.prototype.destroy = function (cb) { var self = this - if (self.destroyed) return onclose && onclose() + if (!cb) cb = noop + if (self.destroyed) return cb(null) self.destroyed = true clearInterval(self.interval) @@ -84,9 +85,9 @@ WebSocketTracker.prototype.destroy = function (onclose) { self.socket.on('error', noop) // ignore all future errors try { - self.socket.destroy(onclose) + self.socket.destroy(cb) } catch (err) { - if (onclose) onclose() + cb(null) } self.socket = null