openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
30 lines (29 loc) • 1.18 kB
JavaScript
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs";
import { i as hasCommandProcessCleanupError } from "./exec-result-DJMhztYN.mjs";
//#region src/infra/lifecycle-write-custody.ts
const owners = resolveGlobalSingleton(Symbol.for("openclaw.lifecycleWriteCustody"), () => /* @__PURE__ */ new Map());
/**
* Records an existing owner's lifetime; this observation grants no write authority.
* Pass the original failure when settling. Uncertain command cleanup retains custody:
* only this handle may release it after independent proof that owned work stopped.
* Without that proof, the fact remains for this process's lifetime, not a timeout.
*/
function beginLifecycleWriteCustody(e) {
const t = owners.get(e) ?? { count: 0 };
t.count++;
owners.set(e, t);
let n = false;
return (r) => {
if (n || hasCommandProcessCleanupError(r)) return;
n = true;
if (--t.count === 0) owners.delete(e);
};
}
function readLifecycleWriteCustody() {
return [...owners].toSorted(([e], [t]) => e.localeCompare(t)).map(([e, { count: t }]) => ({
phase: e,
count: t
}));
}
//#endregion
export { readLifecycleWriteCustody as n, beginLifecycleWriteCustody as t };