Skip to content

Commit

Permalink
fix: prefer queueMicrotask
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 28, 2024
1 parent 2a27dc1 commit ac0c731
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ function destroy (stream, err) {

stream.destroy(err)
} else if (err) {
process.nextTick((stream, err) => {
queueMicrotask((stream, err) => {
stream.emit('error', err)
}, stream, err)
})
}

if (stream.destroyed !== true) {
Expand Down
4 changes: 2 additions & 2 deletions lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class Client extends DispatcherBase {
} else if (util.bodyLength(request.body) == null && util.isIterable(request.body)) {
// Wait a tick in case stream/iterator is ended in the same tick.
this[kResuming] = 1
process.nextTick(resume, this)
queueMicrotask(() => resume(this))
} else {
this[kResume](true)
}
Expand Down Expand Up @@ -548,7 +548,7 @@ function _resume (client, sync) {
} else if (client[kNeedDrain] === 2) {
if (sync) {
client[kNeedDrain] = 1
process.nextTick(emitDrain, client)
queueMicrotask(() => emitDrain(client))
} else {
emitDrain(client)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatcher/pool-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class PoolBase extends DispatcherBase {
this[kClients].push(client)

if (this[kNeedDrain]) {
process.nextTick(() => {
queueMicrotask(() => {
if (this[kNeedDrain]) {
this[kOnDrain](client[kUrl], [this, client])
}
Expand Down

0 comments on commit ac0c731

Please sign in to comment.