12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { IScheduler } from '../Scheduler';
  2. import { Observable } from '../Observable';
  3. /**
  4. * Delays the emission of items from the source Observable by a given timeout or
  5. * until a given Date.
  6. *
  7. * <span class="informal">Time shifts each item by some specified amount of
  8. * milliseconds.</span>
  9. *
  10. * <img src="./img/delay.png" width="100%">
  11. *
  12. * If the delay argument is a Number, this operator time shifts the source
  13. * Observable by that amount of time expressed in milliseconds. The relative
  14. * time intervals between the values are preserved.
  15. *
  16. * If the delay argument is a Date, this operator time shifts the start of the
  17. * Observable execution until the given date occurs.
  18. *
  19. * @example <caption>Delay each click by one second</caption>
  20. * var clicks = Rx.Observable.fromEvent(document, 'click');
  21. * var delayedClicks = clicks.delay(1000); // each click emitted after 1 second
  22. * delayedClicks.subscribe(x => console.log(x));
  23. *
  24. * @example <caption>Delay all clicks until a future date happens</caption>
  25. * var clicks = Rx.Observable.fromEvent(document, 'click');
  26. * var date = new Date('March 15, 2050 12:00:00'); // in the future
  27. * var delayedClicks = clicks.delay(date); // click emitted only after that date
  28. * delayedClicks.subscribe(x => console.log(x));
  29. *
  30. * @see {@link debounceTime}
  31. * @see {@link delayWhen}
  32. *
  33. * @param {number|Date} delay The delay duration in milliseconds (a `number`) or
  34. * a `Date` until which the emission of the source items is delayed.
  35. * @param {Scheduler} [scheduler=async] The IScheduler to use for
  36. * managing the timers that handle the time-shift for each item.
  37. * @return {Observable} An Observable that delays the emissions of the source
  38. * Observable by the specified timeout or Date.
  39. * @method delay
  40. * @owner Observable
  41. */
  42. export declare function delay<T>(this: Observable<T>, delay: number | Date, scheduler?: IScheduler): Observable<T>;