@@ -15,10 +15,49 @@ export function timeoutWith<T, R>(this: Observable<T>, due: number | Date, withO
15
15
/* tslint:enable:max-line-length */
16
16
17
17
/**
18
- * @param due
19
- * @param withObservable
20
- * @param scheduler
21
- * @return {Observable<R>|WebSocketSubject<T>|Observable<T> }
18
+ *
19
+ * Errors if Observable does not emit a value in given time span, in case of which
20
+ * subscribes to the second Observable.
21
+ *
22
+ * <span class="informal">It's a version of `timeout` operator that let's you specify fallback Observable.</span>
23
+ *
24
+ * <img src="./img/timeoutWith.png" width="100%">
25
+ *
26
+ * `timeoutWith` is a variation of `timeout` operator. It behaves exactly the same,
27
+ * still accepting as a first argument either a number or a Date, which control - respectively -
28
+ * when values of source Observable should be emitted or when it should complete.
29
+ *
30
+ * The only difference is that it accepts a second, required parameter. This parameter
31
+ * should be an Observable which will be subscribed when source Observable fails any timeout check.
32
+ * So whenever regular `timeout` would emit an error, `timeoutWith` will instead start re-emitting
33
+ * values from second Observable. Note that this fallback Observable is not checked for timeouts
34
+ * itself, so it can emit values and complete at arbitrary points in time. From the moment of a second
35
+ * subscription, Observable returned from `timeoutWith` simply mirrors fallback stream. When that
36
+ * stream completes, it completes as well.
37
+ *
38
+ * Scheduler, which in case of `timeout` is provided as as second argument, can be still provided
39
+ * here - as a third, optional parameter. It still is used to schedule timeout checks and -
40
+ * as a consequence - when second Observable will be subscribed, since subscription happens
41
+ * immediately after failing check.
42
+ *
43
+ * @example <caption>Add fallback observable</caption>
44
+ * const seconds = Rx.Observable.interval(1000);
45
+ * const minutes = Rx.Observable.interval(60 * 1000);
46
+ *
47
+ * seconds.timeoutWith(900, minutes)
48
+ * .subscribe(
49
+ * value => console.log(value), // After 900ms, will start emitting `minutes`,
50
+ * // since first value of `seconds` will not arrive fast enough.
51
+ * err => console.log(err) // Would be called after 900ms in case of `timeout`,
52
+ * // but here will never be called.
53
+ * );
54
+ *
55
+ * @param {number|Date } due Number specifying period within which Observable must emit values
56
+ * or Date specifying before when Observable should complete
57
+ * @param {Observable<T> } withObservable Observable which will be subscribed if source fails timeout check.
58
+ * @param {Scheduler } [scheduler] Scheduler controlling when timeout checks occur.
59
+ * @return {Observable<T> } Observable that mirrors behaviour of source or, when timeout check fails, of an Observable
60
+ * passed as a second parameter.
22
61
* @method timeoutWith
23
62
* @owner Observable
24
63
*/
0 commit comments