import { makeRequestCall as h, makeRequestCallFromTimer as r } from "./makeRequestCall.es.js";
class l {
  enqueueTask(e) {
    const { queue: t, requestFlush: s } = this;
    t.length || (s(), this.flushing = !0), t[t.length] = e;
  }
  constructor() {
    this.queue = [], this.pendingErrors = [], this.flushing = !1, this.index = 0, this.capacity = 1024, this.flush = () => {
      const { queue: e } = this;
      for (; this.index < e.length; ) {
        const t = this.index;
        if (this.index++, e[t].call(), this.index > this.capacity) {
          for (let s = 0, i = e.length - this.index; s < i; s++)
            e[s] = e[s + this.index];
          e.length -= this.index, this.index = 0;
        }
      }
      e.length = 0, this.index = 0, this.flushing = !1;
    }, this.registerPendingError = (e) => {
      this.pendingErrors.push(e), this.requestErrorThrow();
    }, this.requestFlush = h(this.flush), this.requestErrorThrow = r(() => {
      if (this.pendingErrors.length)
        throw this.pendingErrors.shift();
    });
  }
}
export {
  l as AsapQueue
};
//# sourceMappingURL=AsapQueue.es.js.map
