diff --git a/lib/torrent.js b/lib/torrent.js index 0213f3b0..8f667ffe 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) } }