123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- import {
- e
- } from "./chunk-3OHML7FO.js";
- import {
- v2
- } from "./chunk-Y3WMVFTW.js";
- import {
- T,
- d,
- k,
- m,
- v
- } from "./chunk-ULGDPLM2.js";
- import {
- r,
- t
- } from "./chunk-GZT4BVFP.js";
- // node_modules/@arcgis/core/views/support/QueueProcessor.js
- var u = class {
- constructor(e2, s) {
- this.item = e2, this.controller = s, this.promise = null;
- }
- };
- var l = class {
- constructor(s) {
- 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;
- const t2 = s.scheduler;
- s.priority && r(t2) && (this._task = t2.registerTask(s.priority, this));
- }
- destroy() {
- this.clear(), this._schedule && (this._schedule.remove(), this._schedule = null), this._task && (this._task.remove(), this._task = null);
- }
- get length() {
- return this._processingItems.size + this._queue.length;
- }
- abort(e2) {
- const s = this._controllers.get(e2);
- s && s.abort();
- }
- clear() {
- this._queue.clear();
- const e2 = [];
- this._controllers.forEach((s) => e2.push(s)), this._controllers.clear(), e2.forEach((e3) => e3.abort()), this._processingItems.clear(), this._cancelNext();
- }
- forEach(e2) {
- this._deferreds.forEach((s, t2) => e2(t2));
- }
- get(e2) {
- const s = this._deferreds.get(e2);
- return s ? s.promise : void 0;
- }
- isOngoing(e2) {
- return this._processingItems.has(e2);
- }
- has(e2) {
- return this._deferreds.has(e2);
- }
- pause() {
- this._isPaused || (this._isPaused = true, this._cancelNext());
- }
- push(s, h) {
- const c = this.get(s);
- if (c)
- return c;
- const n = new AbortController();
- let u2 = null;
- h && (u2 = v(h, () => n.abort()));
- const l2 = () => {
- const e2 = this._processingItems.get(s);
- e2 && e2.controller.abort(), _(), a.reject(m());
- }, _ = () => {
- p.remove(), r(u2) && u2.remove(), this._deferreds.delete(s), this._controllers.delete(s), this._queue.remove(s), this._processingItems.delete(s), this._scheduleNext();
- }, p = d(n.signal, l2), a = T();
- return this._deferreds.set(s, a), this._controllers.set(s, n), a.promise.then(_, _), this._queue.push(s), this._scheduleNext(), a.promise;
- }
- last() {
- return this._queue.last();
- }
- peek() {
- return this._queue.peek();
- }
- popLast() {
- return this._queue.popLast();
- }
- reset() {
- const e2 = [];
- this._processingItems.forEach((s) => e2.push(s)), this._processingItems.clear();
- for (const s of e2)
- this._queue.push(s.item), s.controller.abort();
- this._scheduleNext();
- }
- resume() {
- this._isPaused && (this._isPaused = false, this._scheduleNext());
- }
- takeAll() {
- const e2 = [];
- for (; this._queue.length; )
- e2.push(this._queue.pop());
- return this.clear(), e2;
- }
- get running() {
- return !this._isPaused && this._queue.length > 0 && this._processingItems.size < this.concurrency;
- }
- runTask(e2) {
- for (; !e2.done && this._queue.length > 0 && this._processingItems.size < this.concurrency; )
- this._process(this._queue.pop()), e2.madeProgress();
- }
- _scheduleNext() {
- this._task || this._isPaused || this._schedule || (this._schedule = v2(() => {
- this._schedule = null, this._next();
- }));
- }
- _next() {
- for (; this._queue.length > 0 && this._processingItems.size < this.concurrency; )
- this._process(this._queue.pop());
- }
- _cancelNext() {
- this._schedule && (this._schedule.remove(), this._schedule = null);
- }
- _processResult(e2, s) {
- this._canProcessFulfillment(e2) && (this._scheduleNext(), this._deferreds.get(e2.item).resolve(s));
- }
- _processError(e2, s) {
- this._canProcessFulfillment(e2) && (this._scheduleNext(), this._deferreds.get(e2.item).reject(s));
- }
- _canProcessFulfillment(e2) {
- return !!this._deferreds.get(e2.item) && this._processingItems.get(e2.item) === e2;
- }
- _process(e2) {
- if (t(e2))
- return;
- let t2;
- const r2 = new AbortController(), i = new u(e2, r2);
- this._processingItems.set(e2, i);
- try {
- t2 = this.process(e2, r2.signal);
- } catch (o) {
- this._processError(i, o);
- }
- k(t2) ? (i.promise = t2, t2.then((e3) => this._processResult(i, e3), (e3) => this._processError(i, e3))) : this._processResult(i, t2);
- }
- get test() {
- return { update: (e2) => this.runTask(e2) };
- }
- };
- export {
- l
- };
- //# sourceMappingURL=chunk-LMCIAW5S.js.map
|