concatMap.d.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Observable, ObservableInput } from 'rxjs';
  2. /**
  3. * Projects each source value to an Observable which is merged in the output
  4. * Observable, in a serialized fashion waiting for each one to complete before
  5. * merging the next.
  6. *
  7. * <span class="informal">Maps each value to an Observable, then flattens all of
  8. * these inner Observables using {@link concatAll}.</span>
  9. *
  10. * <img src="./img/concatMap.png" width="100%">
  11. *
  12. * Returns an Observable that emits items based on applying a function that you
  13. * supply to each item emitted by the source Observable, where that function
  14. * returns an (so-called "inner") Observable. Each new inner Observable is
  15. * concatenated with the previous inner Observable.
  16. *
  17. * __Warning:__ if source values arrive endlessly and faster than their
  18. * corresponding inner Observables can complete, it will result in memory issues
  19. * as inner Observables amass in an unbounded buffer waiting for their turn to
  20. * be subscribed to.
  21. *
  22. * Note: `concatMap` is equivalent to `mergeMap` with concurrency parameter set
  23. * to `1`.
  24. *
  25. * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
  26. * var clicks = Rx.Observable.fromEvent(document, 'click');
  27. * var result = clicks.concatMap(ev => Rx.Observable.interval(1000).take(4));
  28. * result.subscribe(x => console.log(x));
  29. *
  30. * // Results in the following:
  31. * // (results are not concurrent)
  32. * // For every click on the "document" it will emit values 0 to 3 spaced
  33. * // on a 1000ms interval
  34. * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
  35. *
  36. * @see {@link concat}
  37. * @see {@link concatAll}
  38. * @see {@link concatMapTo}
  39. * @see {@link exhaustMap}
  40. * @see {@link mergeMap}
  41. * @see {@link switchMap}
  42. *
  43. * @param {function(value: T, ?index: number): ObservableInput} project A function
  44. * that, when applied to an item emitted by the source Observable, returns an
  45. * Observable.
  46. * @return {Observable} An Observable that emits the result of applying the
  47. * projection function (and the optional `resultSelector`) to each item emitted
  48. * by the source Observable and taking values from each projected inner
  49. * Observable sequentially.
  50. * @method concatMap
  51. * @owner Observable
  52. */
  53. export declare function concatMap<T, R>(this: Observable<T>, project: (value: T, index: number) => ObservableInput<R>): Observable<R>;