AsapAction.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import { AsyncAction } from './AsyncAction';
  2. import { immediateProvider } from './immediateProvider';
  3. export class AsapAction extends AsyncAction {
  4. constructor(scheduler, work) {
  5. super(scheduler, work);
  6. this.scheduler = scheduler;
  7. this.work = work;
  8. }
  9. requestAsyncId(scheduler, id, delay = 0) {
  10. if (delay !== null && delay > 0) {
  11. return super.requestAsyncId(scheduler, id, delay);
  12. }
  13. scheduler.actions.push(this);
  14. return scheduler._scheduled || (scheduler._scheduled = immediateProvider.setImmediate(scheduler.flush.bind(scheduler, undefined)));
  15. }
  16. recycleAsyncId(scheduler, id, delay = 0) {
  17. var _a;
  18. if (delay != null ? delay > 0 : this.delay > 0) {
  19. return super.recycleAsyncId(scheduler, id, delay);
  20. }
  21. const { actions } = scheduler;
  22. if (id != null && ((_a = actions[actions.length - 1]) === null || _a === void 0 ? void 0 : _a.id) !== id) {
  23. immediateProvider.clearImmediate(id);
  24. if (scheduler._scheduled === id) {
  25. scheduler._scheduled = undefined;
  26. }
  27. }
  28. return undefined;
  29. }
  30. }
  31. //# sourceMappingURL=AsapAction.js.map