From 3fefb4ae21af61f470eb758e2b4cf318580693e2 Mon Sep 17 00:00:00 2001 From: ptaylor Date: Wed, 9 Jun 2021 11:11:11 -0500 Subject: [PATCH] fix(src/asynciterable/operators/timeout.ts): ensure AsyncIterable timeout operator passes its values Typo introduced by linting in a refactor prevented AsyncIterable from passing on its values. fix #325 --- spec/asynciterable-operators/timeout-spec.ts | 36 ++++++++++++++++++++ src/asynciterable/operators/timeout.ts | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 spec/asynciterable-operators/timeout-spec.ts diff --git a/spec/asynciterable-operators/timeout-spec.ts b/spec/asynciterable-operators/timeout-spec.ts new file mode 100644 index 00000000..cabf30ff --- /dev/null +++ b/spec/asynciterable-operators/timeout-spec.ts @@ -0,0 +1,36 @@ +import { hasNext, noNext, delayValue } from '../asynciterablehelpers'; +import { timeout } from 'ix/asynciterable/operators'; +import { as } from 'ix/asynciterable'; +import { TimeoutError } from 'ix/asynciterable/operators/timeout'; + +test('AsyncIterable#timeout drops none', async () => { + const xs = async function* () { + yield await delayValue(1, 50); + yield await delayValue(2, 50); + yield await delayValue(3, 50); + }; + const ys = as(xs()).pipe(timeout(100)); + + const it = ys[Symbol.asyncIterator](); + await hasNext(it, 1); + await hasNext(it, 2); + await hasNext(it, 3); + await noNext(it); +}); + +test('AsyncIterable#timeout throws when delayed', async () => { + const xs = async function* () { + yield await delayValue(1, 50); + yield await delayValue(2, 200); + }; + const ys = as(xs()).pipe(timeout(100)); + + const it = ys[Symbol.asyncIterator](); + await hasNext(it, 1); + try { + await it.next(); + } catch (e) { + expect(e).toBeInstanceOf(TimeoutError); + } + await noNext(it); +}); diff --git a/src/asynciterable/operators/timeout.ts b/src/asynciterable/operators/timeout.ts index 35a56ade..9d42bee3 100644 --- a/src/asynciterable/operators/timeout.ts +++ b/src/asynciterable/operators/timeout.ts @@ -54,7 +54,7 @@ export class TimeoutAsyncIterable extends AsyncIterableX { while (1) { const { type, value } = await safeRace>([ it.next().then((val) => { - return { type: VALUE_TYPE, val }; + return { type: VALUE_TYPE, value: val }; }), sleep(this._dueTime, signal).then(() => { return { type: ERROR_TYPE };