Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9675863

Browse filesBrowse files
ErickWendelruyadorno
authored andcommitted
stream: fix readable stream as async iterator function
Since v19.2 it's not possible to use readableStreams as async iterators (confirmed bug). This patch fixes the problem by reading the Stream.Duplex property from 'streams/duplex' instead of 'streams/legacy' module Fixes: #46141 PR-URL: #46147 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 5ad6c20 commit 9675863
Copy full SHA for 9675863

File tree

Expand file treeCollapse file tree

2 files changed

+29
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-0
lines changed
Open diff view settings
Collapse file

‎lib/stream/promises.js‎

Copy file name to clipboardExpand all lines: lib/stream/promises.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const {
1313
const { pipelineImpl: pl } = require('internal/streams/pipeline');
1414
const { finished } = require('internal/streams/end-of-stream');
1515

16+
require('stream');
17+
1618
function pipeline(...streams) {
1719
return new Promise((resolve, reject) => {
1820
let signal;
Collapse file
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-disable node-core/require-common-first, require-yield */
2+
'use strict';
3+
const { pipeline } = require('node:stream/promises');
4+
{
5+
// Ensure that async iterators can act as readable and writable streams
6+
async function* myCustomReadable() {
7+
yield 'Hello';
8+
yield 'World';
9+
}
10+
11+
const messages = [];
12+
async function* myCustomWritable(stream) {
13+
for await (const chunk of stream) {
14+
messages.push(chunk);
15+
}
16+
}
17+
18+
(async () => {
19+
await pipeline(
20+
myCustomReadable,
21+
myCustomWritable,
22+
);
23+
// Importing here to avoid initializing streams
24+
require('assert').deepStrictEqual(messages, ['Hello', 'World']);
25+
})()
26+
.then(require('../common').mustCall());
27+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.