Front end of the Slack clone application.

Scheduler.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * An execution context and a data structure to order tasks and schedule their
  3. * execution. Provides a notion of (potentially virtual) time, through the
  4. * `now()` getter method.
  5. *
  6. * Each unit of work in a Scheduler is called an {@link Action}.
  7. *
  8. * ```ts
  9. * class Scheduler {
  10. * now(): number;
  11. * schedule(work, delay?, state?): Subscription;
  12. * }
  13. * ```
  14. *
  15. * @class Scheduler
  16. */
  17. export var Scheduler = /*@__PURE__*/ (/*@__PURE__*/ function () {
  18. function Scheduler(SchedulerAction, now) {
  19. if (now === void 0) {
  20. now = Scheduler.now;
  21. }
  22. this.SchedulerAction = SchedulerAction;
  23. this.now = now;
  24. }
  25. /**
  26. * Schedules a function, `work`, for execution. May happen at some point in
  27. * the future, according to the `delay` parameter, if specified. May be passed
  28. * some context object, `state`, which will be passed to the `work` function.
  29. *
  30. * The given arguments will be processed an stored as an Action object in a
  31. * queue of actions.
  32. *
  33. * @param {function(state: ?T): ?Subscription} work A function representing a
  34. * task, or some unit of work to be executed by the Scheduler.
  35. * @param {number} [delay] Time to wait before executing the work, where the
  36. * time unit is implicit and defined by the Scheduler itself.
  37. * @param {T} [state] Some contextual data that the `work` function uses when
  38. * called by the Scheduler.
  39. * @return {Subscription} A subscription in order to be able to unsubscribe
  40. * the scheduled work.
  41. */
  42. Scheduler.prototype.schedule = function (work, delay, state) {
  43. if (delay === void 0) {
  44. delay = 0;
  45. }
  46. return new this.SchedulerAction(this, work).schedule(state, delay);
  47. };
  48. Scheduler.now = Date.now ? Date.now : function () { return +new Date(); };
  49. return Scheduler;
  50. }());
  51. //# sourceMappingURL=Scheduler.js.map