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