Skip to content

Commit

Permalink
fix(timeout): defer error creation until timeout occurs (#5497)
Browse files Browse the repository at this point in the history
- closes #5491
  • Loading branch information
kwonoj authored Jul 5, 2020
1 parent 144b626 commit 3be9840
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 @@ -3,6 +3,9 @@ import { TimeoutError } from '../util/TimeoutError';
import { MonoTypeOperatorFunction, SchedulerLike } 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 @@ -83,5 +86,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 3be9840

Please sign in to comment.