Skip to content
Open
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
4 changes: 3 additions & 1 deletion lib/internal/streams/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ function map(fn, options) {
concurrency = MathFloor(options.concurrency);
}

validateInteger(concurrency, 'concurrency', 1);
if (concurrency !== Infinity) {
validateInteger(concurrency, 'concurrency', 1);
}

return async function* map() {
const ac = new AbortController();
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-stream-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,31 @@ const { setTimeout } = require('timers/promises');
});
}

{
// Allow Infinite concurrency
let resolve;
const promise = new Promise((res) => {
resolve = res;
});
const stream = Readable.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).map(async (item, { signal }) => {
await setTimeout(10 - item, { signal });
if (item === 10) {
resolve();
} else {
await promise;
}

return item;
}, { concurrency: Infinity });

(async () => {
const expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for await (const item of stream) {
assert.strictEqual(item, expected.shift());
}
})().then(common.mustCall());
}

{
// Concurrency result order
const stream = Readable.from([1, 2]).map(async (item, { signal }) => {
Expand Down