-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
readableStream.tee()
doesn't work when using process.nextTick(...)
#39758
Comments
@jasnell @nodejs/streams |
If to replace Edit: The spec uses |
Yeah, I've got this queued up to look at this week. Just haven't yet had the opportunity. |
@jasnell Sorry to bother. I think this is a rather bad bug. Any chance you will have time to look at it? |
Hi, I'll work on it |
Sorry I've been buried and haven't had the opportunity to dig in. It's not a bug in the spec, keep in mind that nextTick is a Node specific concept. |
@szmarczak We had this issue on undici and there we don't really use nextTick in this context? i.e. we always wrap |
Well Node.js streams use |
I've created a PR to address it. However, just to bring more context to the described issue: import {ReadableStream} from 'stream/web';
let controller;
let start = c => (controller = c);
let pull = () => {
if (pull.called) return;
pull.called = true;
process.nextTick(() => {
controller.enqueue(new Uint8Array([102, 111, 111, 98, 97, 114]))
process.nextTick(() => {
controller.close()
});
});
};
const [a, b] = new ReadableStream({start, pull}).tee();
for (const stream of [a, b]) {
const chunks = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
console.log('received:', Buffer.concat(chunks).toString());
} As mentioned by @szmarczak it returns:
On ES Modules, however, when you change it to commonjs it works as expected: - import {ReadableStream} from 'stream/web';
+ const {ReadableStream} = require('stream/web');
The #40901 aims to solve it |
This issue had been solved. Can we close it? |
Version
v16.6.2
Platform
Linux solus 5.13.8-191.current #1 SMP PREEMPT Fri Aug 6 11:29:58 UTC 2021 x86_64 GNU/Linux
Subsystem
stream/web
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
What do you see instead?
Additional information
Deno for reference: https://github.com/denoland/deno/blob/a0285e2eb88f6254f6494b0ecd1878db3a3b2a58/ext/web/06_streams.js#L1465-L1543
/cc @ronag @mcollina @jasnell
The text was updated successfully, but these errors were encountered: