delayWhen.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Observable } from '../Observable';
  2. import { MonoTypeOperatorFunction } from '../interfaces';
  3. /**
  4. * Delays the emission of items from the source Observable by a given time span
  5. * determined by the emissions of another Observable.
  6. *
  7. * <span class="informal">It's like {@link delay}, but the time span of the
  8. * delay duration is determined by a second Observable.</span>
  9. *
  10. * <img src="./img/delayWhen.png" width="100%">
  11. *
  12. * `delayWhen` time shifts each emitted value from the source Observable by a
  13. * time span determined by another Observable. When the source emits a value,
  14. * the `delayDurationSelector` function is called with the source value as
  15. * argument, and should return an Observable, called the "duration" Observable.
  16. * The source value is emitted on the output Observable only when the duration
  17. * Observable emits a value or completes.
  18. *
  19. * Optionally, `delayWhen` takes a second argument, `subscriptionDelay`, which
  20. * is an Observable. When `subscriptionDelay` emits its first value or
  21. * completes, the source Observable is subscribed to and starts behaving like
  22. * described in the previous paragraph. If `subscriptionDelay` is not provided,
  23. * `delayWhen` will subscribe to the source Observable as soon as the output
  24. * Observable is subscribed.
  25. *
  26. * @example <caption>Delay each click by a random amount of time, between 0 and 5 seconds</caption>
  27. * var clicks = Rx.Observable.fromEvent(document, 'click');
  28. * var delayedClicks = clicks.delayWhen(event =>
  29. * Rx.Observable.interval(Math.random() * 5000)
  30. * );
  31. * delayedClicks.subscribe(x => console.log(x));
  32. *
  33. * @see {@link debounce}
  34. * @see {@link delay}
  35. *
  36. * @param {function(value: T): Observable} delayDurationSelector A function that
  37. * returns an Observable for each value emitted by the source Observable, which
  38. * is then used to delay the emission of that item on the output Observable
  39. * until the Observable returned from this function emits a value.
  40. * @param {Observable} subscriptionDelay An Observable that triggers the
  41. * subscription to the source Observable once it emits any value.
  42. * @return {Observable} An Observable that delays the emissions of the source
  43. * Observable by an amount of time specified by the Observable returned by
  44. * `delayDurationSelector`.
  45. * @method delayWhen
  46. * @owner Observable
  47. */
  48. export declare function delayWhen<T>(delayDurationSelector: (value: T) => Observable<any>, subscriptionDelay?: Observable<any>): MonoTypeOperatorFunction<T>;