import CJS_COMPAT_NODE_URL from 'node:url';
import CJS_COMPAT_NODE_PATH from 'node:path';
import CJS_COMPAT_NODE_MODULE from "node:module";

const __filename = CJS_COMPAT_NODE_URL.fileURLToPath(import.meta.url);
const __dirname = CJS_COMPAT_NODE_PATH.dirname(__filename);
const require = CJS_COMPAT_NODE_MODULE.createRequire(import.meta.url);
// ------------------------------------------------------------
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
// ------------------------------------------------------------
import {
  a as f
} from "./chunk-4Y3IMN4V.js";
import {
  a as t
} from "./chunk-HRN2KQZP.js";

// ../node_modules/p-limit/index.js
function d(e) {
  l(e);
  let n = new f(), i = 0, o = /* @__PURE__ */ t(() => {
    i < e && n.size > 0 && (n.dequeue()(), i++);
  }, "resumeNext"), c = /* @__PURE__ */ t(() => {
    i--, o();
  }, "next"), p = /* @__PURE__ */ t(async (u, s, r) => {
    let a = (async () => u(...r))();
    s(a);
    try {
      await a;
    } catch {
    }
    c();
  }, "run"), w = /* @__PURE__ */ t((u, s, r) => {
    new Promise((a) => {
      n.enqueue(a);
    }).then(
      p.bind(void 0, u, s, r)
    ), (async () => (await Promise.resolve(), i < e && o()))();
  }, "enqueue"), m = /* @__PURE__ */ t((u, ...s) => new Promise((r) => {
    w(u, r, s);
  }), "generator");
  return Object.defineProperties(m, {
    activeCount: {
      get: /* @__PURE__ */ t(() => i, "get")
    },
    pendingCount: {
      get: /* @__PURE__ */ t(() => n.size, "get")
    },
    clearQueue: {
      value() {
        n.clear();
      }
    },
    concurrency: {
      get: /* @__PURE__ */ t(() => e, "get"),
      set(u) {
        l(u), e = u, queueMicrotask(() => {
          for (; i < e && n.size > 0; )
            o();
        });
      }
    }
  }), m;
}
t(d, "pLimit");
function g(e, n) {
  let { concurrency: i } = n, o = d(i);
  return (...c) => o(() => e(...c));
}
t(g, "limitFunction");
function l(e) {
  if (!((Number.isInteger(e) || e === Number.POSITIVE_INFINITY) && e > 0))
    throw new TypeError("Expected `concurrency` to be a number from 1 and up");
}
t(l, "validateConcurrency");
export {
  d as default,
  g as limitFunction
};
