import { n as T, r as g } from "./chunk-Njdj7H0c.js";
var L = /* @__PURE__ */ g({
  default: () => k,
  pMapSkip: () => u
});
async function k(o, y, { concurrency: n = Number.POSITIVE_INFINITY, stopOnError: m = !0, signal: a } = {}) {
  return new Promise((_, E) => {
    if (o[Symbol.iterator] === void 0 && o[Symbol.asyncIterator] === void 0) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof o})`);
    if (typeof y != "function") throw new TypeError("Mapper function is required");
    if (!(Number.isSafeInteger(n) && n >= 1 || n === Number.POSITIVE_INFINITY)) throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${n}\` (${typeof n})`);
    const c = [], l = [], d = /* @__PURE__ */ new Map();
    let v = !1, i = !1, w = !1, f = 0, b = 0;
    const M = o[Symbol.iterator] === void 0 ? o[Symbol.asyncIterator]() : o[Symbol.iterator](), x = () => {
      s(a.reason);
    }, S = () => {
      a?.removeEventListener("abort", x);
    }, h = (e) => {
      _(e), S();
    }, s = (e) => {
      v = !0, i = !0, E(e), S();
    };
    a && (a.aborted && s(a.reason), a.addEventListener("abort", x, { once: !0 }));
    const I = async () => {
      if (i) return;
      const e = await M.next(), p = b;
      if (b++, e.done) {
        if (w = !0, f === 0 && !i) {
          if (!m && l.length > 0) {
            s(new AggregateError(l));
            return;
          }
          if (i = !0, d.size === 0) {
            h(c);
            return;
          }
          const t = [];
          for (const [r, N] of c.entries())
            d.get(r) !== u && t.push(N);
          h(t);
        }
        return;
      }
      f++, (async () => {
        try {
          const t = await e.value;
          if (i) return;
          const r = await y(t, p);
          r === u && d.set(p, r), c[p] = r, f--, await I();
        } catch (t) {
          if (m) s(t);
          else {
            l.push(t), f--;
            try {
              await I();
            } catch (r) {
              s(r);
            }
          }
        }
      })();
    };
    (async () => {
      for (let e = 0; e < n; e++) {
        try {
          await I();
        } catch (p) {
          s(p);
          break;
        }
        if (w || v) break;
      }
    })();
  });
}
var u, P = T((() => {
  u = /* @__PURE__ */ Symbol("skip");
}));
export {
  k as n,
  L as r,
  P as t
};

//# sourceMappingURL=p-map-OzxwbPLg.js.map