openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
45 lines (44 loc) • 1.42 kB
JavaScript
import { o as racePromiseWithAbortSignal } from "./src-BPmQBLJp.mjs";
//#region src/plugin-sdk/keyed-async-queue.ts
function enqueueKeyedTask(e) {
e.hooks?.onEnqueue?.();
const t = "keys" in e ? e.keys : [e.key];
const n = "keys" in e ? Promise.allSettled(t.map((t) => e.tails.get(t) ?? Promise.resolve())) : (e.tails.get(e.key) ?? Promise.resolve()).catch(() => void 0);
const r = e.signal ? racePromiseWithAbortSignal(n, e.signal) : n;
const i = n.then(() => {
e.signal?.throwIfAborted();
return e.task();
}).finally(() => {
e.hooks?.onSettle?.();
});
const a = i.then(() => void 0, () => void 0);
for (const n of t) e.tails.set(n, a);
const cleanup = () => {
for (const n of t) if (e.tails.get(n) === a) e.tails.delete(n);
};
a.then(cleanup, cleanup);
return e.signal ? r.then(() => i) : i;
}
/** Small per-key async queue wrapper for plugin runtimes that need serialized work. */
var KeyedAsyncQueue = class {
constructor() {
this.tails = /* @__PURE__ */ new Map();
}
/**
* @deprecated Retained for shipped Plugin SDK compatibility. New callers must
* not depend on queue storage; remove in a declared Plugin SDK breaking window.
*/
getTailMapForTesting() {
return this.tails;
}
enqueue(e, t, n) {
return enqueueKeyedTask({
tails: this.tails,
key: e,
task: t,
...n ? { hooks: n } : {}
});
}
};
//#endregion
export { enqueueKeyedTask as n, KeyedAsyncQueue as t };