Files
openclaw/src/cron/service/locked.ts
T

15 lines
349 B
TypeScript

import type { CronServiceState } from "./state.js";
export async function locked<T>(
state: CronServiceState,
fn: () => Promise<T>,
): Promise<T> {
const next = state.op.then(fn, fn);
// Keep the chain alive even when the operation fails.
state.op = next.then(
() => undefined,
() => undefined,
);
return (await next) as T;
}