Fixes for PR #126

This commit is contained in:
Feross Aboukhadijeh 2016-03-14 19:16:00 -07:00
parent 2fee125554
commit 6df64ffe06
3 changed files with 7 additions and 6 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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