Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AsyncScheduler.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Scheduler } from '../Scheduler';
  2. export class AsyncScheduler extends Scheduler {
  3. constructor(SchedulerAction, now = Scheduler.now) {
  4. super(SchedulerAction, () => {
  5. if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
  6. return AsyncScheduler.delegate.now();
  7. }
  8. else {
  9. return now();
  10. }
  11. });
  12. this.actions = [];
  13. this.active = false;
  14. this.scheduled = undefined;
  15. }
  16. schedule(work, delay = 0, state) {
  17. if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
  18. return AsyncScheduler.delegate.schedule(work, delay, state);
  19. }
  20. else {
  21. return super.schedule(work, delay, state);
  22. }
  23. }
  24. flush(action) {
  25. const { actions } = this;
  26. if (this.active) {
  27. actions.push(action);
  28. return;
  29. }
  30. let error;
  31. this.active = true;
  32. do {
  33. if (error = action.execute(action.state, action.delay)) {
  34. break;
  35. }
  36. } while (action = actions.shift());
  37. this.active = false;
  38. if (error) {
  39. while (action = actions.shift()) {
  40. action.unsubscribe();
  41. }
  42. throw error;
  43. }
  44. }
  45. }
  46. //# sourceMappingURL=AsyncScheduler.js.map