diff --git a/spec/asynciterable-operators/flatmap-spec.ts b/spec/asynciterable-operators/flatmap-spec.ts index e3fccb02..c5890530 100644 --- a/spec/asynciterable-operators/flatmap-spec.ts +++ b/spec/asynciterable-operators/flatmap-spec.ts @@ -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); diff --git a/src/util/returniterator.ts b/src/util/returniterator.ts index 8e1836ad..6f34b9a5 100644 --- a/src/util/returniterator.ts +++ b/src/util/returniterator.ts @@ -2,7 +2,7 @@ * @ignore */ export function returnIterator(it: Iterator) { - if (typeof it.return === 'function') { + if (typeof it?.return === 'function') { it.return(); } } @@ -11,7 +11,7 @@ export function returnIterator(it: Iterator) { * @ignore */ export async function returnAsyncIterator(it: AsyncIterator): Promise { - if (typeof it.return === 'function') { + if (typeof it?.return === 'function') { await it.return(); } }