delay.js 2.0 KB

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