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:
authorChocobozzz <me@florianbigard.com>2018-09-27 09:59:21 +0300
committerGitHub <noreply@github.com>2018-09-27 09:59:21 +0300
commit5b7c5eebf41c9e1e1fe8e9e1d4a6ad06e93e7430 (patch)
tree4eaff3d54623a6b21981b24b85307d76573109ec
parent7e0d447c3e8cc0c4739fa3c06e13de331da6bc2b (diff)
Use a update wire wrapper instead
-rw-r--r--lib/torrent.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 4ceca06..8f667ff 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -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)
}
}
@@ -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))