Front end of the Slack clone application.

AsyncScheduler.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6. };
  7. var Scheduler_1 = require('../Scheduler');
  8. var AsyncScheduler = (function (_super) {
  9. __extends(AsyncScheduler, _super);
  10. function AsyncScheduler() {
  11. _super.apply(this, arguments);
  12. this.actions = [];
  13. /**
  14. * A flag to indicate whether the Scheduler is currently executing a batch of
  15. * queued actions.
  16. * @type {boolean}
  17. */
  18. this.active = false;
  19. /**
  20. * An internal ID used to track the latest asynchronous task such as those
  21. * coming from `setTimeout`, `setInterval`, `requestAnimationFrame`, and
  22. * others.
  23. * @type {any}
  24. */
  25. this.scheduled = undefined;
  26. }
  27. AsyncScheduler.prototype.flush = function (action) {
  28. var actions = this.actions;
  29. if (this.active) {
  30. actions.push(action);
  31. return;
  32. }
  33. var error;
  34. this.active = true;
  35. do {
  36. if (error = action.execute(action.state, action.delay)) {
  37. break;
  38. }
  39. } while (action = actions.shift()); // exhaust the scheduler queue
  40. this.active = false;
  41. if (error) {
  42. while (action = actions.shift()) {
  43. action.unsubscribe();
  44. }
  45. throw error;
  46. }
  47. };
  48. return AsyncScheduler;
  49. }(Scheduler_1.Scheduler));
  50. exports.AsyncScheduler = AsyncScheduler;
  51. //# sourceMappingURL=AsyncScheduler.js.map