Skip to content

Commit

Permalink
fix(timeout): defer error creation until timeout occurs (ReactiveX#5497)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj authored and benlesh committed Jul 5, 2020
1 parent 7437993 commit dca4773
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/internal/operators/timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { TimeoutError } from '../util/TimeoutError';
import { MonoTypeOperatorFunction, SchedulerAction, SchedulerLike, TeardownLogic } from '../types';
import { timeoutWith } from './timeoutWith';
import { throwError } from '../observable/throwError';
import { defer } from '../observable/defer';

function timeoutErrFactory() { return throwError(new TimeoutError()); }

/**
*
Expand Down Expand Up @@ -88,5 +91,5 @@ import { throwError } from '../observable/throwError';
*/
export function timeout<T>(due: number | Date,
scheduler: SchedulerLike = async): MonoTypeOperatorFunction<T> {
return timeoutWith(due, throwError(new TimeoutError()), scheduler);
return timeoutWith(due, defer(timeoutErrFactory), scheduler);
}

0 comments on commit dca4773

Please sign in to comment.