11import { Observable } from '../Observable' ;
2- import { MonoTypeOperatorFunction } from '../types' ;
2+ import { MonoTypeOperatorFunction , ObservableInput } from '../types' ;
33import { concat } from '../observable/concat' ;
44import { take } from './take' ;
55import { ignoreElements } from './ignoreElements' ;
66import { mapTo } from './mapTo' ;
77import { mergeMap } from './mergeMap' ;
8+ import { innerFrom } from '../observable/innerFrom' ;
89
910/** @deprecated The `subscriptionDelay` parameter will be removed in v8. */
1011export function delayWhen < T > (
11- delayDurationSelector : ( value : T , index : number ) => Observable < any > ,
12+ delayDurationSelector : ( value : T , index : number ) => ObservableInput < any > ,
1213 subscriptionDelay : Observable < any >
1314) : 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 > ;
1516
1617/**
1718 * 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) =>
2627 * a time span determined by another Observable. When the source emits a value,
2728 * the `delayDurationSelector` function is called with the value emitted from
2829 * 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.
3133 *
3234 * The source value is emitted on the output Observable only when the "duration"
3335 * 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) =>
7678 * @see {@link audit }
7779 * @see {@link auditTime }
7880 *
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.
8588 * @return A function that returns an Observable that delays the emissions of
8689 * the source Observable by an amount of time specified by the Observable
8790 * returned by `delayDurationSelector`.
8891 */
8992export function delayWhen < T > (
90- delayDurationSelector : ( value : T , index : number ) => Observable < any > ,
93+ delayDurationSelector : ( value : T , index : number ) => ObservableInput < any > ,
9194 subscriptionDelay ?: Observable < any >
9295) : MonoTypeOperatorFunction < T > {
9396 if ( subscriptionDelay ) {
@@ -96,5 +99,5 @@ export function delayWhen<T>(
9699 concat ( subscriptionDelay . pipe ( take ( 1 ) , ignoreElements ( ) ) , source . pipe ( delayWhen ( delayDurationSelector ) ) ) ;
97100 }
98101
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 ) ) ) ;
100103}
0 commit comments