UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

23 lines (22 loc) • 607 B
import pMap from "p-map"; //#region packages/memory-host-sdk/src/host/concurrency.ts /** Run tasks with bounded concurrency, stopping admission and draining active work on failure. */ async function runWithConcurrency(e, t) { const n = /* @__PURE__ */ new Set(); try { return await pMap(e, (e) => { const t = Promise.resolve().then(e); n.add(t); t.then(() => n.delete(t), () => n.delete(t)); return t; }, { concurrency: Math.max(1, Math.floor(t)), stopOnError: true }); } catch (e) { await Promise.allSettled(n); throw e; } } //#endregion export { runWithConcurrency as t };