diff --git a/src/Lazy/takeUntil.ts b/src/Lazy/takeUntil.ts index 678c07ce..a35ea7e9 100644 --- a/src/Lazy/takeUntil.ts +++ b/src/Lazy/takeUntil.ts @@ -30,6 +30,10 @@ function asyncSequential( return this; }, async next(_concurrent) { + if (end) { + return { done: true, value: undefined }; + } + const { done, value } = await iterator.next(_concurrent); if (done || end) { return { done: true, value: undefined }; diff --git a/test/Lazy/takeUntil.spec.ts b/test/Lazy/takeUntil.spec.ts index 08c9dc36..46d02228 100644 --- a/test/Lazy/takeUntil.spec.ts +++ b/test/Lazy/takeUntil.spec.ts @@ -3,6 +3,7 @@ import { delay, filter, map, + peek, pipe, range, takeUntil, @@ -95,6 +96,20 @@ describe("takeUntil", function () { expect(res).toEqual([12, 14]); }); + it("should be able to take the element", async function () { + const fn = jest.fn(); + const res = await pipe( + toAsync([3, 3, 1, 0, 0]), + peek(fn), + map((a) => delay(100, a)), + takeUntil((a) => a < 3), + toArray, + ); + + expect(fn).toHaveBeenCalledTimes(3); + expect(res).toEqual([3, 3, 1]); + }, 350); + it("should be able to take the element until the callback result is truthy concurrently", async function () { const res = await pipe( toAsync(range(1, 20)),