| 1 |
import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; |
| 2 |
import { exhaustMap } from './exhaustMap'; |
| 3 |
import { identity } from '../util/identity'; |
| 4 |
|
| 5 |
/** |
| 6 |
* Converts a higher-order Observable into a first-order Observable by dropping |
| 7 |
* inner Observables while the previous inner Observable has not yet completed. |
| 8 |
* |
| 9 |
* <span class="informal">Flattens an Observable-of-Observables by dropping the |
| 10 |
* next inner Observables while the current inner is still executing.</span> |
| 11 |
* |
| 12 |
*  |
| 13 |
* |
| 14 |
* `exhaustAll` subscribes to an Observable that emits Observables, also known as a |
| 15 |
* higher-order Observable. Each time it observes one of these emitted inner |
| 16 |
* Observables, the output Observable begins emitting the items emitted by that |
| 17 |
* inner Observable. So far, it behaves like {@link mergeAll}. However, |
| 18 |
* `exhaustAll` ignores every new inner Observable if the previous Observable has |
| 19 |
* not yet completed. Once that one completes, it will accept and flatten the |
| 20 |
* next inner Observable and repeat this process. |
| 21 |
* |
| 22 |
* ## Example |
| 23 |
* |
| 24 |
* Run a finite timer for each click, only if there is no currently active timer |
| 25 |
* |
| 26 |
* ```ts |
| 27 |
* import { fromEvent, map, interval, take, exhaustAll } from 'rxjs'; |
| 28 |
* |
| 29 |
* const clicks = fromEvent(document, 'click'); |
| 30 |
* const higherOrder = clicks.pipe( |
| 31 |
* map(() => interval(1000).pipe(take(5))) |
| 32 |
* ); |
| 33 |
* const result = higherOrder.pipe(exhaustAll()); |
| 34 |
* result.subscribe(x => console.log(x)); |
| 35 |
* ``` |
| 36 |
* |
| 37 |
* @see {@link combineLatestAll} |
| 38 |
* @see {@link concatAll} |
| 39 |
* @see {@link switchAll} |
| 40 |
* @see {@link switchMap} |
| 41 |
* @see {@link mergeAll} |
| 42 |
* @see {@link exhaustMap} |
| 43 |
* @see {@link zipAll} |
| 44 |
* |
| 45 |
* @return A function that returns an Observable that takes a source of |
| 46 |
* Observables and propagates the first Observable exclusively until it |
| 47 |
* completes before subscribing to the next. |
| 48 |
*/ |
| 49 |
export function exhaustAll<O extends ObservableInput<any>>(): OperatorFunction<O, ObservedValueOf<O>> { |
| 50 |
return exhaustMap(identity); |
| 51 |
} |