@gguf/claw
Version:
Multi-channel AI gateway with extensible messaging integrations
52 lines (51 loc) • 2.28 kB
TypeScript
/**
* Dedicated error type thrown when a queued command is rejected because
* its lane was cleared. Callers that fire-and-forget enqueued tasks can
* catch (or ignore) this specific type to avoid unhandled-rejection noise.
*/
export declare class CommandLaneClearedError extends Error {
constructor(lane?: string);
}
export declare function setCommandLaneConcurrency(lane: string, maxConcurrent: number): void;
export declare function enqueueCommandInLane<T>(lane: string, task: () => Promise<T>, opts?: {
warnAfterMs?: number;
onWait?: (waitMs: number, queuedAhead: number) => void;
}): Promise<T>;
export declare function enqueueCommand<T>(task: () => Promise<T>, opts?: {
warnAfterMs?: number;
onWait?: (waitMs: number, queuedAhead: number) => void;
}): Promise<T>;
export declare function getQueueSize(lane?: string): number;
export declare function getTotalQueueSize(): number;
export declare function clearCommandLane(lane?: string): number;
/**
* Reset all lane runtime state to idle. Used after SIGUSR1 in-process
* restarts where interrupted tasks' finally blocks may not run, leaving
* stale active task IDs that permanently block new work from draining.
*
* Bumps lane generation and clears execution counters so stale completions
* from old in-flight tasks are ignored. Queued entries are intentionally
* preserved — they represent pending user work that should still execute
* after restart.
*
* After resetting, drains any lanes that still have queued entries so
* preserved work is pumped immediately rather than waiting for a future
* `enqueueCommandInLane()` call (which may never come).
*/
export declare function resetAllLanes(): void;
/**
* Returns the total number of actively executing tasks across all lanes
* (excludes queued-but-not-started entries).
*/
export declare function getActiveTaskCount(): number;
/**
* Wait for all currently active tasks across all lanes to finish.
* Polls at a short interval; resolves when no tasks are active or
* when `timeoutMs` elapses (whichever comes first).
*
* New tasks enqueued after this call are ignored — only tasks that are
* already executing are waited on.
*/
export declare function waitForActiveTasks(timeoutMs: number): Promise<{
drained: boolean;
}>;