From c65ba98d964234efea4c109f5983c227c3ff864c Mon Sep 17 00:00:00 2001 From: Alexandru Branza Date: Sun, 22 Jul 2018 20:18:13 +0300 Subject: [PATCH] Set Timeout to Waiting for All Torrents to Close --- server/streams.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server/streams.js b/server/streams.js index ad436da..5f458ad 100755 --- a/server/streams.js +++ b/server/streams.js @@ -121,28 +121,32 @@ const basicTorrentData = (torrent, cb) => { } const closeAll = (cb) => { + if (updateInterval) clearInterval(updateInterval) + updateInterval = false if (concurrencyInterval) clearInterval(concurrencyInterval) - concurrencyInterval = false - setTimeout(() => { - cb && cb() - cb = false - }, 500) + concurrencyInterval = false let ticks = _.size(streams) if (!ticks) return cb() + const closeTimeout = setTimeout(() => { + cb && cb() + cb = false + }, 30000) // 30 sec timeout + _.each(streams, (el, ij) => { cancelTorrent(ij, () => { ticks-- if (!ticks) { + clearTimeout(closeTimeout) cb && cb() } }, false, true)