Skip to content

Commit

Permalink
perf: avoid setImmediate if body is reading (#3210)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed May 7, 2024
1 parent 94c9aa9 commit d51dabc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ class BodyReadable extends Readable {
// tick as it is created, then a user who is waiting for a
// promise (i.e micro tick) for installing a 'error' listener will
// never get a chance and will always encounter an unhandled exception.
setImmediate(() => {
if (!this[kReading]) {
setImmediate(() => {
callback(err)
})
} else {
callback(err)
})
}
}

on (ev, ...args) {
Expand Down

0 comments on commit d51dabc

Please sign in to comment.