UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

20 lines (19 loc) • 649 B
import { setTimeout } from "node:timers/promises"; //#region src/infra/acquire-with-wait.ts /** Retry only acquisition, keeping the deadline independent of wall-clock changes. */ async function acquireWithWait(e) { const t = e.now ?? performance.now.bind(performance); let n = e.pollIntervalMs; for (;;) try { return await e.acquire(); } catch (r) { const i = e.shouldRetry(r); if (!i) throw r; const a = e.deadlineMs - t(); if (a <= 0) throw r; await (e.sleep ?? setTimeout)(Math.min(i === true ? n : i.delayMs, a)); n = Math.min(n * 2, e.maxPollIntervalMs ?? e.pollIntervalMs); } } //#endregion export { acquireWithWait as t };