UNPKG

akm-cli

Version:

akm (Agent Knowledge Manager) — a portable, local-first capability library for AI agents. Discover, load, share, and improve reusable skills, scripts, workflows, and knowledge across any shell-capable coding agent, including Claude Code, OpenCode, and Cur

29 lines (28 loc) • 1.05 kB
// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. export function armAbortDeadline(controller, options) { const { timeoutMs, reason } = options; if (timeoutMs === null || timeoutMs === undefined) { return { disarm: () => { }, timedOut: () => false }; } const setTimeoutImpl = options.setTimeoutFn ?? setTimeout; const clearTimeoutImpl = options.clearTimeoutFn ?? clearTimeout; let fired = false; let timer = setTimeoutImpl(() => { timer = undefined; fired = true; controller.abort(new Error(reason)); }, timeoutMs); // A pending deadline must never be the reason the process stays alive. timer?.unref?.(); return { disarm: () => { if (timer !== undefined) { clearTimeoutImpl(timer); timer = undefined; } }, timedOut: () => fired, }; }