Skip to content

Commit

Permalink
perf: early return when handling "drained" event
Browse files Browse the repository at this point in the history
We only need to find one non-drained stream for this logic, so we can
bail early if we find one. This should slightly improve performance.
  • Loading branch information
EvanHahn committed Jan 19, 2024
1 parent db857d3 commit ca7f4e2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/multi-core-index-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ class MultiCoreIndexStream extends Readable {
#handleDrained() {
let drained = true
for (const stream of this.#streams.keys()) {
if (!stream.drained) drained = false
if (!stream.drained) {
drained = false
break
}
}
if (drained === this.#drained && !drained) return
this.#drained = drained
Expand Down

0 comments on commit ca7f4e2

Please sign in to comment.