Skip to content
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: make from read one at a time #33201

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/internal/streams/from.js
Expand Up @@ -33,6 +33,8 @@ function from(Readable, iterable, opts) {

const readable = new Readable({
objectMode: true,
highWaterMark: 1,
// TODO(ronag): What options should be allowed?
...opts
});

Expand Down
26 changes: 25 additions & 1 deletion test/parallel/test-readable-from.js
Expand Up @@ -159,6 +159,29 @@ async function asTransformStream() {
}
}

async function endWithError() {
async function* generate() {
yield 1;
yield 2;
yield Promise.reject('Boum');
}

const stream = Readable.from(generate());

const expected = [1, 2];

try {
for await (const chunk of stream) {
strictEqual(chunk, expected.shift());
}
throw new Error();
} catch (err) {
strictEqual(expected.length, 0);
strictEqual(err, 'Boum');
}
}


Promise.all([
toReadableBasicSupport(),
toReadableSyncIterator(),
Expand All @@ -168,5 +191,6 @@ Promise.all([
toReadableOnData(),
toReadableOnDataNonObject(),
destroysTheStreamWhenThrowing(),
asTransformStream()
asTransformStream(),
endWithError()
]).then(mustCall());