queue.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. var QueueAction_1 = require('./QueueAction');
  3. var QueueScheduler_1 = require('./QueueScheduler');
  4. /**
  5. *
  6. * Queue Scheduler
  7. *
  8. * <span class="informal">Put every next task on a queue, instead of executing it immediately</span>
  9. *
  10. * `queue` scheduler, when used with delay, behaves the same as {@link async} scheduler.
  11. *
  12. * When used without delay, it schedules given task synchronously - executes it right when
  13. * it is scheduled. However when called recursively, that is when inside the scheduled task,
  14. * another task is scheduled with queue scheduler, instead of executing immediately as well,
  15. * that task will be put on a queue and wait for current one to finish.
  16. *
  17. * This means that when you execute task with `queue` scheduler, you are sure it will end
  18. * before any other task scheduled with that scheduler will start.
  19. *
  20. * @examples <caption>Schedule recursively first, then do something</caption>
  21. *
  22. * Rx.Scheduler.queue.schedule(() => {
  23. * Rx.Scheduler.queue.schedule(() => console.log('second')); // will not happen now, but will be put on a queue
  24. *
  25. * console.log('first');
  26. * });
  27. *
  28. * // Logs:
  29. * // "first"
  30. * // "second"
  31. *
  32. *
  33. * @example <caption>Reschedule itself recursively</caption>
  34. *
  35. * Rx.Scheduler.queue.schedule(function(state) {
  36. * if (state !== 0) {
  37. * console.log('before', state);
  38. * this.schedule(state - 1); // `this` references currently executing Action,
  39. * // which we reschedule with new state
  40. * console.log('after', state);
  41. * }
  42. * }, 0, 3);
  43. *
  44. * // In scheduler that runs recursively, you would expect:
  45. * // "before", 3
  46. * // "before", 2
  47. * // "before", 1
  48. * // "after", 1
  49. * // "after", 2
  50. * // "after", 3
  51. *
  52. * // But with queue it logs:
  53. * // "before", 3
  54. * // "after", 3
  55. * // "before", 2
  56. * // "after", 2
  57. * // "before", 1
  58. * // "after", 1
  59. *
  60. *
  61. * @static true
  62. * @name queue
  63. * @owner Scheduler
  64. */
  65. exports.queue = new QueueScheduler_1.QueueScheduler(QueueAction_1.QueueAction);
  66. //# sourceMappingURL=queue.js.map