Skip to content

Commit f90e4d9

Browse files
committed
same fix for flatMap
1 parent 3aadc06 commit f90e4d9

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

lib/internal/streams/operators.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,13 @@ async function toArray(options) {
232232
return result;
233233
}
234234

235-
async function* flatMap(fn, options) {
236-
for await (const val of this.map(fn, options)) {
237-
yield* val;
238-
}
235+
function flatMap(fn, options) {
236+
const values = this.map(fn, options);
237+
return async function* flatMap() {
238+
for await (const val of values) {
239+
yield* val;
240+
}
241+
}();
239242
}
240243

241244
function toIntegerOrInfinity(number) {

test/parallel/test-stream-flatMap.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,11 @@ function oneTo5() {
109109

110110
{
111111
// Error cases
112-
assert.rejects(async () => {
113-
// eslint-disable-next-line no-unused-vars
114-
for await (const unused of Readable.from([1]).flatMap(1));
115-
}, /ERR_INVALID_ARG_TYPE/).then(common.mustCall());
116-
assert.rejects(async () => {
117-
// eslint-disable-next-line no-unused-vars
118-
for await (const _ of Readable.from([1]).flatMap((x) => x, {
119-
concurrency: 'Foo'
120-
}));
121-
}, /ERR_OUT_OF_RANGE/).then(common.mustCall());
122-
assert.rejects(async () => {
123-
// eslint-disable-next-line no-unused-vars
124-
for await (const _ of Readable.from([1]).flatMap((x) => x, 1));
125-
}, /ERR_INVALID_ARG_TYPE/).then(common.mustCall());
112+
assert.throws(() => Readable.from([1]).flatMap(1), /ERR_INVALID_ARG_TYPE/);
113+
assert.throws(() => Readable.from([1]).flatMap((x) => x, {
114+
concurrency: 'Foo'
115+
}), /ERR_OUT_OF_RANGE/);
116+
assert.throws(() => Readable.from([1]).flatMap((x) => x, 1), /ERR_INVALID_ARG_TYPE/);
126117
}
127118
{
128119
// Test result is a Readable

0 commit comments

Comments
 (0)