Skip to content

Commit

Permalink
fix(flatmap): flatMap shouldn't throw when the input size is smaller …
Browse files Browse the repository at this point in the history
…than concurrent (#367)

fix #366
  • Loading branch information
trxcllnt committed May 18, 2024
1 parent eab2f10 commit dffd344
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions spec/asynciterable-operators/flatmap-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ test('AsyncIterable#flatMap with range', async () => {
expect(await toArray(ys)).toEqual([0, 0, 0, 1, 1, 2]);
});

test(`AsyncIterable#flatMap with fewer inputs than max concurrent doesn't throw`, async () => {
const xs = of(1, 2);
const ys = xs.pipe(flatMap(async (x) => range(0, x), 3));

expect(await toArray(ys)).toEqual([0, 0, 1]);
});

test('AsyncIterable#flatMap selector returns throw', async () => {
const err = new Error();
const xs = of(1, 2, 3);
Expand Down
4 changes: 2 additions & 2 deletions src/util/returniterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @ignore
*/
export function returnIterator<T>(it: Iterator<T>) {
if (typeof it.return === 'function') {
if (typeof it?.return === 'function') {
it.return();
}
}
Expand All @@ -11,7 +11,7 @@ export function returnIterator<T>(it: Iterator<T>) {
* @ignore
*/
export async function returnAsyncIterator<T>(it: AsyncIterator<T>): Promise<void> {
if (typeof it.return === 'function') {
if (typeof it?.return === 'function') {
await it.return();
}
}

0 comments on commit dffd344

Please sign in to comment.