1
1
import { Observable } from '../Observable' ;
2
- import { MonoTypeOperatorFunction } from '../types' ;
2
+ import { MonoTypeOperatorFunction , ObservableInput } from '../types' ;
3
3
import { concat } from '../observable/concat' ;
4
4
import { take } from './take' ;
5
5
import { ignoreElements } from './ignoreElements' ;
6
6
import { mapTo } from './mapTo' ;
7
7
import { mergeMap } from './mergeMap' ;
8
+ import { innerFrom } from '../observable/innerFrom' ;
8
9
9
10
/** @deprecated The `subscriptionDelay` parameter will be removed in v8. */
10
11
export function delayWhen < T > (
11
- delayDurationSelector : ( value : T , index : number ) => Observable < any > ,
12
+ delayDurationSelector : ( value : T , index : number ) => ObservableInput < any > ,
12
13
subscriptionDelay : Observable < any >
13
14
) : MonoTypeOperatorFunction < T > ;
14
- export function delayWhen < T > ( delayDurationSelector : ( value : T , index : number ) => Observable < any > ) : MonoTypeOperatorFunction < T > ;
15
+ export function delayWhen < T > ( delayDurationSelector : ( value : T , index : number ) => ObservableInput < any > ) : MonoTypeOperatorFunction < T > ;
15
16
16
17
/**
17
18
* Delays the emission of items from the source Observable by a given time span
@@ -26,8 +27,9 @@ export function delayWhen<T>(delayDurationSelector: (value: T, index: number) =>
26
27
* a time span determined by another Observable. When the source emits a value,
27
28
* the `delayDurationSelector` function is called with the value emitted from
28
29
* the source Observable as the first argument to the `delayDurationSelector`.
29
- * The `delayDurationSelector` function should return an Observable, called
30
- * the "duration" Observable.
30
+ * The `delayDurationSelector` function should return an {@link ObservableInput},
31
+ * that is internally converted to an Observable that is called the "duration"
32
+ * Observable.
31
33
*
32
34
* The source value is emitted on the output Observable only when the "duration"
33
35
* Observable emits ({@link guide/glossary-and-semantics#next next}s) any value.
@@ -76,18 +78,19 @@ export function delayWhen<T>(delayDurationSelector: (value: T, index: number) =>
76
78
* @see {@link audit }
77
79
* @see {@link auditTime }
78
80
*
79
- * @param {function(value: T, index: number): Observable } delayDurationSelector A function that
80
- * returns an Observable for each value emitted by the source Observable, which
81
- * is then used to delay the emission of that item on the output Observable
82
- * until the Observable returned from this function emits a value.
83
- * @param {Observable } subscriptionDelay An Observable that triggers the
84
- * subscription to the source Observable once it emits any value.
81
+ * @param delayDurationSelector A function that returns an `ObservableInput` for
82
+ * each `value` emitted by the source Observable, which is then used to delay the
83
+ * emission of that `value` on the output Observable until the `ObservableInput`
84
+ * returned from this function emits a next value. When called, beside `value`,
85
+ * this function receives a zero-based `index` of the emission order.
86
+ * @param subscriptionDelay An Observable that triggers the subscription to the
87
+ * source Observable once it emits any value.
85
88
* @return A function that returns an Observable that delays the emissions of
86
89
* the source Observable by an amount of time specified by the Observable
87
90
* returned by `delayDurationSelector`.
88
91
*/
89
92
export function delayWhen < T > (
90
- delayDurationSelector : ( value : T , index : number ) => Observable < any > ,
93
+ delayDurationSelector : ( value : T , index : number ) => ObservableInput < any > ,
91
94
subscriptionDelay ?: Observable < any >
92
95
) : MonoTypeOperatorFunction < T > {
93
96
if ( subscriptionDelay ) {
@@ -96,5 +99,5 @@ export function delayWhen<T>(
96
99
concat ( subscriptionDelay . pipe ( take ( 1 ) , ignoreElements ( ) ) , source . pipe ( delayWhen ( delayDurationSelector ) ) ) ;
97
100
}
98
101
99
- return mergeMap ( ( value , index ) => delayDurationSelector ( value , index ) . pipe ( take ( 1 ) , mapTo ( value ) ) ) ;
102
+ return mergeMap ( ( value , index ) => innerFrom ( delayDurationSelector ( value , index ) ) . pipe ( take ( 1 ) , mapTo ( value ) ) ) ;
100
103
}
0 commit comments