1 import { MonoTypeOperatorFunction, SchedulerLike } from '../types';
4 * Errors if Observable does not emit a value in given time span.
6 * <span class="informal">Timeouts on Observable that doesn't emit values fast enough.</span>
10 * `timeout` operator accepts as an argument either a number or a Date.
12 * If number was provided, it returns an Observable that behaves like a source
13 * Observable, unless there is a period of time where there is no value emitted.
14 * So if you provide `100` as argument and first value comes after 50ms from
15 * the moment of subscription, this value will be simply re-emitted by the resulting
16 * Observable. If however after that 100ms passes without a second value being emitted,
17 * stream will end with an error and source Observable will be unsubscribed.
18 * These checks are performed throughout whole lifecycle of Observable - from the moment
19 * it was subscribed to, until it completes or errors itself. Thus every value must be
20 * emitted within specified period since previous value.
22 * If provided argument was Date, returned Observable behaves differently. It throws
23 * if Observable did not complete before provided Date. This means that periods between
24 * emission of particular values do not matter in this case. If Observable did not complete
25 * before provided Date, source Observable will be unsubscribed. Other than that, resulting
26 * stream behaves just as source Observable.
28 * `timeout` accepts also a Scheduler as a second parameter. It is used to schedule moment (or moments)
29 * when returned Observable will check if source stream emitted value or completed.
32 * Check if ticks are emitted within certain timespan
34 * import { interval } from 'rxjs';
35 * import { timeout } from 'rxjs/operators';
37 * const seconds = interval(1000);
39 * seconds.pipe(timeout(1100)) // Let's use bigger timespan to be safe,
40 * // since `interval` might fire a bit later then scheduled.
42 * value => console.log(value), // Will emit numbers just as regular `interval` would.
43 * err => console.log(err), // Will never be called.
46 * seconds.pipe(timeout(900))
48 * value => console.log(value), // Will never be called.
49 * err => console.log(err), // Will emit error before even first value is emitted,
50 * // since it did not arrive within 900ms period.
54 * Use Date to check if Observable completed
56 * import { interval } from 'rxjs';
57 * import { timeout } from 'rxjs/operators';
59 * const seconds = interval(1000);
62 * timeout(new Date("December 17, 2020 03:24:00")),
65 * value => console.log(value), // Will emit values as regular `interval` would
66 * // until December 17, 2020 at 03:24:00.
67 * err => console.log(err) // On December 17, 2020 at 03:24:00 it will emit an error,
68 * // since Observable did not complete by then.
71 * @see {@link timeoutWith}
73 * @param {number|Date} due Number specifying period within which Observable must emit values
74 * or Date specifying before when Observable should complete
75 * @param {SchedulerLike} [scheduler] Scheduler controlling when timeout checks occur.
76 * @return {Observable<T>} Observable that mirrors behaviour of source, unless timeout checks fail.
80 export declare function timeout<T>(due: number | Date, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;