-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: fix enqueue race condition on esm modules
stream: use nextTick on close PR-URL: #40901 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
1 parent
a6e7cf5
commit 8cf507a
Showing
2 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { mustCall } from '../common/index.mjs'; | ||
import { ReadableStream } from 'stream/web'; | ||
import assert from 'assert'; | ||
|
||
{ | ||
// Test tee() with close in the nextTick after enqueue | ||
async function read(stream) { | ||
const chunks = []; | ||
for await (const chunk of stream) | ||
chunks.push(chunk); | ||
return Buffer.concat(chunks).toString(); | ||
} | ||
|
||
const [r1, r2] = new ReadableStream({ | ||
start(controller) { | ||
process.nextTick(() => { | ||
controller.enqueue(new Uint8Array([102, 111, 111, 98, 97, 114])); | ||
|
||
process.nextTick(() => { | ||
controller.close(); | ||
}); | ||
}); | ||
} | ||
}).tee(); | ||
|
||
(async () => { | ||
const [dataReader1, dataReader2] = await Promise.all([ | ||
read(r1), | ||
read(r2), | ||
]); | ||
|
||
assert.strictEqual(dataReader1, dataReader2); | ||
assert.strictEqual(dataReader1, 'foobar'); | ||
assert.strictEqual(dataReader2, 'foobar'); | ||
})().then(mustCall()); | ||
} |