Skip to content

Commit

Permalink
fix(src/asynciterable/operators/timeout.ts): ensure AsyncIterable tim…
Browse files Browse the repository at this point in the history
…eout operator passes its values (#327)

Typo introduced by linting in a refactor prevented AsyncIterable from passing on its values.

fix #325
  • Loading branch information
trxcllnt authored Jun 9, 2021
1 parent 0bdb6c3 commit f5a213a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions spec/asynciterable-operators/timeout-spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
2 changes: 1 addition & 1 deletion src/asynciterable/operators/timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class TimeoutAsyncIterable<TSource> extends AsyncIterableX<TSource> {
while (1) {
const { type, value } = await safeRace<TimeoutOperation<TSource>>([
it.next().then((val) => {
return { type: VALUE_TYPE, val };
return { type: VALUE_TYPE, value: val };
}),
sleep(this._dueTime, signal).then(() => {
return { type: ERROR_TYPE };
Expand Down

0 comments on commit f5a213a

Please sign in to comment.