Skip to content

Commit

Permalink
Use a update wire wrapper instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Sep 27, 2018
1 parent 7e0d447 commit 5b7c5ee
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/torrent.js
Expand Up @@ -1138,7 +1138,17 @@ class Torrent extends EventEmitter {
const ite = randomIterate(this.wires)
let wire
while ((wire = ite())) {
this._updateWire(wire)
this._updateWireWrapper(wire)
}
}

_updateWireWrapper (wire) {
const self = this

if (typeof window !== 'undefined' && typeof window.requestIdleCallback === 'function') {
window.requestIdleCallback(function () { self._updateWire(wire) })
} else {
self._updateWire(wire)
}
}

Expand All @@ -1156,11 +1166,7 @@ class Torrent extends EventEmitter {
if (wire.requests.length >= minOutstandingRequests) return
const maxOutstandingRequests = getBlockPipelineLength(wire, PIPELINE_MAX_DURATION)

if (typeof window !== 'undefined' && typeof window.requestIdleCallback === 'function') {
window.requestIdleCallback(function () { trySelectWire(false) || trySelectWire(true) })
} else {
trySelectWire(false) || trySelectWire(true)
}
trySelectWire(false) || trySelectWire(true)

function genPieceFilterFunc (start, end, tried, rank) {
return i => i >= start && i <= end && !(i in tried) && wire.peerPieces.get(i) && (!rank || rank(i))
Expand Down

0 comments on commit 5b7c5ee

Please sign in to comment.