diff options
author | ftreesmilo <58193105+ftreesmilo@users.noreply.github.com> | 2020-12-08 04:26:09 +0300 |
---|---|---|
committer | Kaylee <34007889+KayleePop@users.noreply.github.com> | 2020-12-11 06:40:19 +0300 |
commit | 2d78a30a72072b859336f8d9340398d6bb2169e0 (patch) | |
tree | a509cbfc2587905ca630300df6a93023c40801e4 /lib/torrent.js | |
parent | 38f4f9c846b036fcd4b53a96ff151bc105b38c11 (diff) |
replace process.nextTick with queueMicrotask
Diffstat (limited to 'lib/torrent.js')
-rw-r--r-- | lib/torrent.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 8787e53..201a452 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -25,6 +25,7 @@ const speedometer = require('speedometer') const utMetadata = require('ut_metadata') const utPex = require('ut_pex') // browser exclude const utp = require('utp-native') // browser exclude +const queueMicrotask = require('queue-microtask') const File = require('./file') const Peer = require('./peer') @@ -202,7 +203,7 @@ class Torrent extends EventEmitter { // Attempt to set infoHash property synchronously this.infoHash = parsedTorrent.infoHash this._debugId = parsedTorrent.infoHash.toString('hex').substring(0, 7) - process.nextTick(() => { + queueMicrotask(() => { if (this.destroyed) return this._onParsedTorrent(parsedTorrent) }) @@ -586,7 +587,7 @@ class Torrent extends EventEmitter { this.store.get(index, (err, buf) => { if (this.destroyed) return cb(new Error('torrent is destroyed')) - if (err) return process.nextTick(cb, null) // ignore error + if (err) return queueMicrotask(cb, null) // ignore error sha1(buf, hash => { if (this.destroyed) return cb(new Error('torrent is destroyed')) @@ -1031,7 +1032,7 @@ class Torrent extends EventEmitter { this.emit('wire', wire, addr) if (this.metadata) { - process.nextTick(() => { + queueMicrotask(() => { // This allows wire.handshake() to be called (by Peer.onHandshake) before any // messages get sent on the wire this._onWireWithMetadata(wire) @@ -1129,7 +1130,7 @@ class Torrent extends EventEmitter { _updateSelections () { if (!this.ready || this.destroyed) return - process.nextTick(() => { + queueMicrotask(() => { this._gcSelections() }) this._updateInterest() @@ -1591,7 +1592,7 @@ class Torrent extends EventEmitter { }) function onUpdateTick () { - process.nextTick(() => { self._update() }) + queueMicrotask(() => { self._update() }) } return true |