Skip to content

Commit

Permalink
fix: wait for flush to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Dec 10, 2021
1 parent 73c851f commit d992152
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,9 @@ class ThreadStream extends EventEmitter {
throw new Error('the worker is ending')
}

if (this[kImpl].flushing && this[kImpl].buf.length + data.length >= MAX_STRING) {
if (this[kImpl].buf.length + data.length >= MAX_STRING) {
try {
writeSync(this)
this[kImpl].flushing = true
} catch (err) {
destroy(this, err)
return false
Expand Down Expand Up @@ -416,7 +415,11 @@ function writeSync (stream) {
process.nextTick(drain, stream)
}
}
stream[kImpl].flushing = false

if (stream[kImpl].flushing) {
// TODO (fix): What if flushing? Wait for flushing to finish?
stream[kImpl].flushing = false
}

while (stream[kImpl].buf.length !== 0) {
const writeIndex = Atomics.load(stream[kImpl].state, WRITE_INDEX)
Expand Down

0 comments on commit d992152

Please sign in to comment.