UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

53 lines (52 loc) • 1.7 kB
import { a as captureAsyncWorkTracker } from "./async-work-scope-BXagjUap.mjs"; import { AsyncLocalStorage } from "node:async_hooks"; //#region src/cron/mutation-completion.ts const mutationMethods = /* @__PURE__ */ new Set([ "cron.add", "cron.update", "cron.remove", "cron.run", "cron.scratch.set" ]); const currentMutation = new AsyncLocalStorage(); /** One in-process invocation may preserve only the effect its actual mutation owner accepted. */ function createCronMutationCompletion(e) { if (!mutationMethods.has(e)) return; const t = { method: e, open: true, committed: false, ...e === "cron.run" ? { trackAdmission: captureAsyncWorkTracker() } : {} }; return { isCommitted: () => t.committed, run: async (e) => { if (!t.open) throw new Error("Cron mutation completion has already settled."); try { return await currentMutation.run(t, e); } finally { t.open = false; } } }; } /** Capture resource ownership before acknowledgement, independently of authorization. */ function captureCronRunAdmissionTracker() { const e = currentMutation.getStore(); const t = e?.trackAdmission; if (!e?.open || e.method !== "cron.run" || !t) return; return async (n) => { if (!e.open) throw new Error("Cron mutation completion has already settled."); return await t(n); }; } /** Capture at the effect owner; a late callback cannot mark a later invocation. */ function captureCronMutationCommit(e) { const t = currentMutation.getStore(); if (!t?.open || t.method !== e) return; return () => { if (t.open) t.committed = true; }; } //#endregion export { captureCronRunAdmissionTracker as n, createCronMutationCompletion as r, captureCronMutationCommit as t };