a zip code crypto-currency system good for red ONLY

AsyncScheduler.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Scheduler } from '../Scheduler';
  2. export class AsyncScheduler extends Scheduler {
  3. constructor() {
  4. super(...arguments);
  5. this.actions = [];
  6. /**
  7. * A flag to indicate whether the Scheduler is currently executing a batch of
  8. * queued actions.
  9. * @type {boolean}
  10. */
  11. this.active = false;
  12. /**
  13. * An internal ID used to track the latest asynchronous task such as those
  14. * coming from `setTimeout`, `setInterval`, `requestAnimationFrame`, and
  15. * others.
  16. * @type {any}
  17. */
  18. this.scheduled = undefined;
  19. }
  20. flush(action) {
  21. const { actions } = this;
  22. if (this.active) {
  23. actions.push(action);
  24. return;
  25. }
  26. let error;
  27. this.active = true;
  28. do {
  29. if (error = action.execute(action.state, action.delay)) {
  30. break;
  31. }
  32. } while (action = actions.shift()); // exhaust the scheduler queue
  33. this.active = false;
  34. if (error) {
  35. while (action = actions.shift()) {
  36. action.unsubscribe();
  37. }
  38. throw error;
  39. }
  40. }
  41. }
  42. //# sourceMappingURL=AsyncScheduler.js.map