Skip to content

Commit

Permalink
stream: load stream module when using stream/promises
Browse files Browse the repository at this point in the history
  • Loading branch information
ErickWendel committed Jan 13, 2023
1 parent 47ca37d commit 88a656a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
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
22 changes: 11 additions & 11 deletions test/parallel/test-stream3-pipeline-async-iterator.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/* eslint-disable node-core/require-common-first, require-yield */
'use strict';
const common = require('../common');
const assert = require('assert');
const { pipeline } = require('node:stream/promises');

{
// Ensure that async iterators can act as readable and writable streams
async function* myCustomReadable() {
yield 'Hello';
yield 'World';
}

// eslint-disable-next-line require-yield
const messages = [];
async function* myCustomWritable(stream) {
const messages = [];
for await (const chunk of stream) {
messages.push(chunk);
}
assert.deepStrictEqual(messages, ['Hello', 'World']);
}

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

0 comments on commit 88a656a

Please sign in to comment.