queue.js 645 B

1234567891011121314151617181920212223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Queue = void 0;
  4. /**
  5. * This is a custom stateless queue to track concurrent async fs calls.
  6. * It increments a counter whenever a call is queued and decrements it
  7. * as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
  8. */
  9. class Queue {
  10. onQueueEmpty;
  11. count = 0;
  12. constructor(onQueueEmpty) {
  13. this.onQueueEmpty = onQueueEmpty;
  14. }
  15. enqueue() {
  16. this.count++;
  17. }
  18. dequeue(error, output) {
  19. if (--this.count <= 0 || error)
  20. this.onQueueEmpty(error, output);
  21. }
  22. }
  23. exports.Queue = Queue;