Front end of the Slack clone application.

Scheduler.js 1.8KB

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