Queue.js 812 B

1234567891011121314151617181920212223242526
  1. class Queue {
  2. constructor() {
  3. E(this, "queue", []);
  4. E(this, "currentAction")
  5. }
  6. async append(e) {
  7. var t, r;
  8. this.queue.length === 0 || ((t = this.currentAction) == null ? void 0 : t.type) === e.type && this.queue.length === 1 ? (this.queue = [],
  9. this.queue.push(e),
  10. await this.go()) : (((r = this.queue[this.queue.length - 1]) == null ? void 0 : r.type) === e.type && this.queue.pop(),
  11. this.queue.push(e))
  12. }
  13. async go() {
  14. if (this.queue.length !== 0) {
  15. const e = this.queue[0];
  16. this.currentAction = e,
  17. await e.action(),
  18. this.currentAction = void 0,
  19. this.queue.splice(0, 1),
  20. await this.go()
  21. }
  22. }
  23. async reject() {
  24. this.queue = []
  25. }
  26. }