-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Stream: Error trying to paginate data using Readable.take operator #44026
Comments
cc @nodejs/streams |
This seems expected as any of those operators consume the stream. Maybe we should just document them better? |
it seems confusing to the userland. Shouldn't these operators try consuming the stream the same way? Or in this case, change the When I read What do you think? |
This looks confusing, I possibly overlooked the detail that the following works: import { Readable } from 'node:stream'
const data = Readable.from(['a', 'b', 'c', 'd'])
data.take(2).forEach(x => console.log(x, 'take 2'));
data.drop(1).take(1).forEach(x => console.log(x, 'drop 1 + take 1'));
/*
a take 2
d take 2
c drop 1 + take 1
*/ Which I didn't expect to. @benjamingr @ronag wdyt? |
Should I try fixing it? @nodejs/streams |
Yes! I would like to see what the fix look like. |
This also happening on regular const { Readable, compose} = require('node:stream');
compose(
Readable.from(['a', 'b', 'c', 'd']),
async function*(stream) {
for await (const chunk of stream) {
yield chunk;
return;
}
}
).forEach(x => console.log(x)) This will print out 'a' and then fail on |
Version
18.4
Platform
Darwin
Subsystem
No response
What steps will reproduce the bug?
I was trying to paginate results from a Stream using the .take operator but it's throwing an
AbortError
or
However, using the code below keeps the stream working and prints the array without one char
or
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
Consume chunks as specified
What do you see instead?
// AbortError: The operation was aborted
Additional information
@benjamingr
The text was updated successfully, but these errors were encountered: