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
path: root/lib
diff options
context:
space:
mode:
authorftreesmilo <58193105+ftreesmilo@users.noreply.github.com>2020-12-08 04:26:09 +0300
committerKaylee <34007889+KayleePop@users.noreply.github.com>2020-12-11 06:40:19 +0300
commit2d78a30a72072b859336f8d9340398d6bb2169e0 (patch)
treea509cbfc2587905ca630300df6a93023c40801e4 /lib
parent38f4f9c846b036fcd4b53a96ff151bc105b38c11 (diff)
replace process.nextTick with queueMicrotask
Diffstat (limited to 'lib')
-rw-r--r--lib/conn-pool.js5
-rw-r--r--lib/file.js3
-rw-r--r--lib/server.js3
-rw-r--r--lib/torrent.js11
4 files changed, 13 insertions, 9 deletions
diff --git a/lib/conn-pool.js b/lib/conn-pool.js
index 5746ca5..80aa87f 100644
--- a/lib/conn-pool.js
+++ b/lib/conn-pool.js
@@ -2,6 +2,7 @@ const arrayRemove = require('unordered-array-remove')
const debug = require('debug')('webtorrent:conn-pool')
const net = require('net') // browser exclude
const utp = require('utp-native') // browser exclude
+const queueMicrotask = require('queue-microtask')
const Peer = require('./peer')
@@ -95,14 +96,14 @@ class ConnPool {
try {
this.utpServer.close(cb)
} catch (err) {
- if (cb) process.nextTick(cb)
+ if (cb) queueMicrotask(cb)
}
}
try {
this.tcpServer.close(cb)
} catch (err) {
- if (cb) process.nextTick(cb)
+ if (cb) queueMicrotask(cb)
}
this.tcpServer = null
diff --git a/lib/file.js b/lib/file.js
index 3e75091..d9a10e0 100644
--- a/lib/file.js
+++ b/lib/file.js
@@ -7,6 +7,7 @@ const streamToBlob = require('stream-to-blob')
const streamToBlobURL = require('stream-to-blob-url')
const streamToBuffer = require('stream-with-known-length-to-buffer')
const FileStream = require('./file-stream')
+const queueMicrotask = require('queue-microtask')
class File extends EventEmitter {
constructor (torrent, file) {
@@ -81,7 +82,7 @@ class File extends EventEmitter {
createReadStream (opts) {
if (this.length === 0) {
const empty = new PassThrough()
- process.nextTick(() => {
+ queueMicrotask(() => {
empty.end()
})
return empty
diff --git a/lib/server.js b/lib/server.js
index cc33159..85b4573 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -4,6 +4,7 @@ const http = require('http')
const mime = require('mime')
const pump = require('pump')
const rangeParser = require('range-parser')
+const queueMicrotask = require('queue-microtask')
function Server (torrent, opts = {}) {
const server = http.createServer()
@@ -40,7 +41,7 @@ function Server (torrent, opts = {}) {
// Only call `server.close` if user has not called it already
if (!cb) cb = () => {}
- if (closed) process.nextTick(cb)
+ if (closed) queueMicrotask(cb)
else server.close(cb)
torrent = null
}
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