chunk-LMCIAW5S.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import {
  2. e
  3. } from "./chunk-3OHML7FO.js";
  4. import {
  5. v2
  6. } from "./chunk-Y3WMVFTW.js";
  7. import {
  8. T,
  9. d,
  10. k,
  11. m,
  12. v
  13. } from "./chunk-ULGDPLM2.js";
  14. import {
  15. r,
  16. t
  17. } from "./chunk-GZT4BVFP.js";
  18. // node_modules/@arcgis/core/views/support/QueueProcessor.js
  19. var u = class {
  20. constructor(e2, s) {
  21. this.item = e2, this.controller = s, this.promise = null;
  22. }
  23. };
  24. var l = class {
  25. constructor(s) {
  26. this._deferreds = new Map(), this._controllers = new Map(), this._processingItems = new Map(), this._isPaused = false, this._schedule = null, this._task = null, this.concurrency = 1, s.concurrency && (this.concurrency = s.concurrency), this._queue = new e(s.peeker), this.process = s.process;
  27. const t2 = s.scheduler;
  28. s.priority && r(t2) && (this._task = t2.registerTask(s.priority, this));
  29. }
  30. destroy() {
  31. this.clear(), this._schedule && (this._schedule.remove(), this._schedule = null), this._task && (this._task.remove(), this._task = null);
  32. }
  33. get length() {
  34. return this._processingItems.size + this._queue.length;
  35. }
  36. abort(e2) {
  37. const s = this._controllers.get(e2);
  38. s && s.abort();
  39. }
  40. clear() {
  41. this._queue.clear();
  42. const e2 = [];
  43. this._controllers.forEach((s) => e2.push(s)), this._controllers.clear(), e2.forEach((e3) => e3.abort()), this._processingItems.clear(), this._cancelNext();
  44. }
  45. forEach(e2) {
  46. this._deferreds.forEach((s, t2) => e2(t2));
  47. }
  48. get(e2) {
  49. const s = this._deferreds.get(e2);
  50. return s ? s.promise : void 0;
  51. }
  52. isOngoing(e2) {
  53. return this._processingItems.has(e2);
  54. }
  55. has(e2) {
  56. return this._deferreds.has(e2);
  57. }
  58. pause() {
  59. this._isPaused || (this._isPaused = true, this._cancelNext());
  60. }
  61. push(s, h) {
  62. const c = this.get(s);
  63. if (c)
  64. return c;
  65. const n = new AbortController();
  66. let u2 = null;
  67. h && (u2 = v(h, () => n.abort()));
  68. const l2 = () => {
  69. const e2 = this._processingItems.get(s);
  70. e2 && e2.controller.abort(), _(), a.reject(m());
  71. }, _ = () => {
  72. p.remove(), r(u2) && u2.remove(), this._deferreds.delete(s), this._controllers.delete(s), this._queue.remove(s), this._processingItems.delete(s), this._scheduleNext();
  73. }, p = d(n.signal, l2), a = T();
  74. return this._deferreds.set(s, a), this._controllers.set(s, n), a.promise.then(_, _), this._queue.push(s), this._scheduleNext(), a.promise;
  75. }
  76. last() {
  77. return this._queue.last();
  78. }
  79. peek() {
  80. return this._queue.peek();
  81. }
  82. popLast() {
  83. return this._queue.popLast();
  84. }
  85. reset() {
  86. const e2 = [];
  87. this._processingItems.forEach((s) => e2.push(s)), this._processingItems.clear();
  88. for (const s of e2)
  89. this._queue.push(s.item), s.controller.abort();
  90. this._scheduleNext();
  91. }
  92. resume() {
  93. this._isPaused && (this._isPaused = false, this._scheduleNext());
  94. }
  95. takeAll() {
  96. const e2 = [];
  97. for (; this._queue.length; )
  98. e2.push(this._queue.pop());
  99. return this.clear(), e2;
  100. }
  101. get running() {
  102. return !this._isPaused && this._queue.length > 0 && this._processingItems.size < this.concurrency;
  103. }
  104. runTask(e2) {
  105. for (; !e2.done && this._queue.length > 0 && this._processingItems.size < this.concurrency; )
  106. this._process(this._queue.pop()), e2.madeProgress();
  107. }
  108. _scheduleNext() {
  109. this._task || this._isPaused || this._schedule || (this._schedule = v2(() => {
  110. this._schedule = null, this._next();
  111. }));
  112. }
  113. _next() {
  114. for (; this._queue.length > 0 && this._processingItems.size < this.concurrency; )
  115. this._process(this._queue.pop());
  116. }
  117. _cancelNext() {
  118. this._schedule && (this._schedule.remove(), this._schedule = null);
  119. }
  120. _processResult(e2, s) {
  121. this._canProcessFulfillment(e2) && (this._scheduleNext(), this._deferreds.get(e2.item).resolve(s));
  122. }
  123. _processError(e2, s) {
  124. this._canProcessFulfillment(e2) && (this._scheduleNext(), this._deferreds.get(e2.item).reject(s));
  125. }
  126. _canProcessFulfillment(e2) {
  127. return !!this._deferreds.get(e2.item) && this._processingItems.get(e2.item) === e2;
  128. }
  129. _process(e2) {
  130. if (t(e2))
  131. return;
  132. let t2;
  133. const r2 = new AbortController(), i = new u(e2, r2);
  134. this._processingItems.set(e2, i);
  135. try {
  136. t2 = this.process(e2, r2.signal);
  137. } catch (o) {
  138. this._processError(i, o);
  139. }
  140. k(t2) ? (i.promise = t2, t2.then((e3) => this._processResult(i, e3), (e3) => this._processError(i, e3))) : this._processResult(i, t2);
  141. }
  142. get test() {
  143. return { update: (e2) => this.runTask(e2) };
  144. }
  145. };
  146. export {
  147. l
  148. };
  149. //# sourceMappingURL=chunk-LMCIAW5S.js.map