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.

VirtualTimeScheduler.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /** PURE_IMPORTS_START tslib,_AsyncAction,_AsyncScheduler PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { AsyncAction } from './AsyncAction';
  4. import { AsyncScheduler } from './AsyncScheduler';
  5. var VirtualTimeScheduler = /*@__PURE__*/ (function (_super) {
  6. tslib_1.__extends(VirtualTimeScheduler, _super);
  7. function VirtualTimeScheduler(SchedulerAction, maxFrames) {
  8. if (SchedulerAction === void 0) {
  9. SchedulerAction = VirtualAction;
  10. }
  11. if (maxFrames === void 0) {
  12. maxFrames = Number.POSITIVE_INFINITY;
  13. }
  14. var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
  15. _this.maxFrames = maxFrames;
  16. _this.frame = 0;
  17. _this.index = -1;
  18. return _this;
  19. }
  20. VirtualTimeScheduler.prototype.flush = function () {
  21. var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
  22. var error, action;
  23. while ((action = actions.shift()) && (this.frame = action.delay) <= maxFrames) {
  24. if (error = action.execute(action.state, action.delay)) {
  25. break;
  26. }
  27. }
  28. if (error) {
  29. while (action = actions.shift()) {
  30. action.unsubscribe();
  31. }
  32. throw error;
  33. }
  34. };
  35. VirtualTimeScheduler.frameTimeFactor = 10;
  36. return VirtualTimeScheduler;
  37. }(AsyncScheduler));
  38. export { VirtualTimeScheduler };
  39. var VirtualAction = /*@__PURE__*/ (function (_super) {
  40. tslib_1.__extends(VirtualAction, _super);
  41. function VirtualAction(scheduler, work, index) {
  42. if (index === void 0) {
  43. index = scheduler.index += 1;
  44. }
  45. var _this = _super.call(this, scheduler, work) || this;
  46. _this.scheduler = scheduler;
  47. _this.work = work;
  48. _this.index = index;
  49. _this.active = true;
  50. _this.index = scheduler.index = index;
  51. return _this;
  52. }
  53. VirtualAction.prototype.schedule = function (state, delay) {
  54. if (delay === void 0) {
  55. delay = 0;
  56. }
  57. if (!this.id) {
  58. return _super.prototype.schedule.call(this, state, delay);
  59. }
  60. this.active = false;
  61. var action = new VirtualAction(this.scheduler, this.work);
  62. this.add(action);
  63. return action.schedule(state, delay);
  64. };
  65. VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
  66. if (delay === void 0) {
  67. delay = 0;
  68. }
  69. this.delay = scheduler.frame + delay;
  70. var actions = scheduler.actions;
  71. actions.push(this);
  72. actions.sort(VirtualAction.sortActions);
  73. return true;
  74. };
  75. VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
  76. if (delay === void 0) {
  77. delay = 0;
  78. }
  79. return undefined;
  80. };
  81. VirtualAction.prototype._execute = function (state, delay) {
  82. if (this.active === true) {
  83. return _super.prototype._execute.call(this, state, delay);
  84. }
  85. };
  86. VirtualAction.sortActions = function (a, b) {
  87. if (a.delay === b.delay) {
  88. if (a.index === b.index) {
  89. return 0;
  90. }
  91. else if (a.index > b.index) {
  92. return 1;
  93. }
  94. else {
  95. return -1;
  96. }
  97. }
  98. else if (a.delay > b.delay) {
  99. return 1;
  100. }
  101. else {
  102. return -1;
  103. }
  104. };
  105. return VirtualAction;
  106. }(AsyncAction));
  107. export { VirtualAction };
  108. //# sourceMappingURL=VirtualTimeScheduler.js.map