Skip to content

Commit

Permalink
Set Timeout to Waiting for All Torrents to Close
Browse files Browse the repository at this point in the history
  • Loading branch information
jaruba committed Jul 22, 2018
1 parent 6b81e94 commit c65ba98
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions server/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c65ba98

Please sign in to comment.