exhaustMap.d.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Observable, ObservableInput } from 'rxjs';
  2. /**
  3. * Projects each source value to an Observable which is merged in the output
  4. * Observable only if the previous projected Observable has completed.
  5. *
  6. * <span class="informal">Maps each value to an Observable, then flattens all of
  7. * these inner Observables using {@link exhaust}.</span>
  8. *
  9. * <img src="./img/exhaustMap.png" width="100%">
  10. *
  11. * Returns an Observable that emits items based on applying a function that you
  12. * supply to each item emitted by the source Observable, where that function
  13. * returns an (so-called "inner") Observable. When it projects a source value to
  14. * an Observable, the output Observable begins emitting the items emitted by
  15. * that projected Observable. However, `exhaustMap` ignores every new projected
  16. * Observable if the previous projected Observable has not yet completed. Once
  17. * that one completes, it will accept and flatten the next projected Observable
  18. * and repeat this process.
  19. *
  20. * @example <caption>Run a finite timer for each click, only if there is no currently active timer</caption>
  21. * var clicks = fromEvent(document, 'click');
  22. * var result = clicks.pipe(exhaustMap((ev) => Rx.Observable.interval(1000).take(5)));
  23. * result.subscribe(x => console.log(x));
  24. *
  25. * @see {@link concatMap}
  26. * @see {@link exhaust}
  27. * @see {@link mergeMap}
  28. * @see {@link switchMap}
  29. *
  30. * @param {function(value: T, ?index: number): ObservableInput} project A function
  31. * that, when applied to an item emitted by the source Observable, returns an
  32. * Observable.
  33. * @return {Observable} An Observable containing projected Observables
  34. * of each item of the source, ignoring projected Observables that start before
  35. * their preceding Observable has completed.
  36. */
  37. export declare function exhaustMap<T, R>(this: Observable<T>, project: (value: T, index: number) => ObservableInput<R>): Observable<R>;