diff --git a/src/internal/operators/timeout.ts b/src/internal/operators/timeout.ts index ed9411fe29..86ae099a18 100644 --- a/src/internal/operators/timeout.ts +++ b/src/internal/operators/timeout.ts @@ -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()); } /** * @@ -83,5 +86,5 @@ import { throwError } from '../observable/throwError'; */ export function timeout(due: number | Date, scheduler: SchedulerLike = async): MonoTypeOperatorFunction { - return timeoutWith(due, throwError(new TimeoutError()), scheduler); + return timeoutWith(due, defer(timeoutErrFactory), scheduler); }