UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.21 kB
import{a as captureAsyncWorkTracker}from"./async-work-scope-DBcxYU4O.mjs";import{AsyncLocalStorage}from"node:async_hooks"; //!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;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}}}}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)}}function captureCronMutationCommit(e){const t=currentMutation.getStore();if(!t?.open||t.method!==e)return;return()=>{if(t.open)t.committed=true}}export{captureCronRunAdmissionTracker as n,createCronMutationCompletion as r,captureCronMutationCommit as t};