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: fix readable stream as async iterator function #46147

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/stream/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const {
const { pipelineImpl: pl } = require('internal/streams/pipeline');
const { finished } = require('internal/streams/end-of-stream');

require('stream');

function pipeline(...streams) {
return new Promise((resolve, reject) => {
let signal;
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-stream3-pipeline-async-iterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable node-core/require-common-first, require-yield */
'use strict';
const { pipeline } = require('node:stream/promises');
{
// Ensure that async iterators can act as readable and writable streams
async function* myCustomReadable() {
yield 'Hello';
yield 'World';
}

const messages = [];
async function* myCustomWritable(stream) {
for await (const chunk of stream) {
messages.push(chunk);
}
}

(async () => {
await pipeline(
myCustomReadable,
myCustomWritable,
);
// Importing here to avoid initializing streams
require('assert').deepStrictEqual(messages, ['Hello', 'World']);
})()
.then(require('../common').mustCall());
}