Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-01-26 22:18:47 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-01-26 22:18:47 +0300
commitdf77c9474303167485525946a62163d009efc6f8 (patch)
tree52f46eca6fc1935365e1f66ac4714bc64c5b5cc6
parent2570b37e1f7b90ae89530c4b4fb58d90b048aa7a (diff)
after client.destroy(), no "torrent" event should be emitted
Fixes #254
-rw-r--r--index.js3
-rw-r--r--test/basic.js23
2 files changed, 23 insertions, 3 deletions
diff --git a/index.js b/index.js
index 6015104..27f7f48 100644
--- a/index.js
+++ b/index.js
@@ -207,6 +207,9 @@ WebTorrent.prototype.seed = function (input, opts, onseed) {
createTorrent(input, opts, function (err, torrentBuf) {
if (err) return self.emit('error', err)
+ // if client was destroyed asyncronously, bail early (or `add` will throw)
+ if (self.destroyed) return
+
self.add(torrentBuf, opts, function (torrent) {
var tasks = [function (cb) {
torrent.storage.load(streams, cb)
diff --git a/test/basic.js b/test/basic.js
index 1e3db44..241594e 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -84,15 +84,32 @@ test('client.seed (Buffer, Blob)', function (t) {
}
})
-test('throw if add or seed after destroy', function (t) {
+test('after client.destroy(), throw on client.add() or client.seed()', function (t) {
+ t.plan(3)
+
var client = new WebTorrent({ dht: false, tracker: false })
- client.destroy()
+ client.destroy(function () {
+ t.pass('client destroyed')
+ })
t.throws(function () {
client.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash)
})
t.throws(function () {
client.seed(new Buffer('sup'))
})
- t.end()
})
+test('after client.destroy(), no "torrent" event should be emitted', function (t) {
+ t.plan(1)
+
+ var client = new WebTorrent({ dht: false, tracker: false })
+ client.add(leaves, function () {
+ t.fail('unexpected "torrent" event')
+ })
+ client.seed(leavesBook, function () {
+ t.fail('unexpected "torrent" event')
+ })
+ client.destroy(function () {
+ t.pass('client destroyed')
+ })
+})