Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

QueueAction.ts 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { AsyncAction } from './AsyncAction';
  2. import { Subscription } from '../Subscription';
  3. import { QueueScheduler } from './QueueScheduler';
  4. import { SchedulerAction } from '../types';
  5. /**
  6. * We need this JSDoc comment for affecting ESDoc.
  7. * @ignore
  8. * @extends {Ignored}
  9. */
  10. export class QueueAction<T> extends AsyncAction<T> {
  11. constructor(protected scheduler: QueueScheduler,
  12. protected work: (this: SchedulerAction<T>, state?: T) => void) {
  13. super(scheduler, work);
  14. }
  15. public schedule(state?: T, delay: number = 0): Subscription {
  16. if (delay > 0) {
  17. return super.schedule(state, delay);
  18. }
  19. this.delay = delay;
  20. this.state = state;
  21. this.scheduler.flush(this);
  22. return this;
  23. }
  24. public execute(state: T, delay: number): any {
  25. return (delay > 0 || this.closed) ?
  26. super.execute(state, delay) :
  27. this._execute(state, delay) ;
  28. }
  29. protected requestAsyncId(scheduler: QueueScheduler, id?: any, delay: number = 0): any {
  30. // If delay exists and is greater than 0, or if the delay is null (the
  31. // action wasn't rescheduled) but was originally scheduled as an async
  32. // action, then recycle as an async action.
  33. if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
  34. return super.requestAsyncId(scheduler, id, delay);
  35. }
  36. // Otherwise flush the scheduler starting with this action.
  37. return scheduler.flush(this);
  38. }
  39. }