diff --git a/src/internal/operators/timeout.ts b/src/internal/operators/timeout.ts index b049e730018..f43e6701db6 100644 --- a/src/internal/operators/timeout.ts +++ b/src/internal/operators/timeout.ts @@ -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()); } /** * @@ -88,5 +91,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); }