import type { TaskQueueSnapshot } from './task-queue-summary.ts'; import type { PendingTask, SchedulingPolicy, TaskQueueOptions, TaskQueueSummary, TaskResult } from './task-queue-types.ts'; /** Callback invoked when a task completes, fails, or expires. Implementation-private. */ type CompletionCallback = (result: TaskResult) => void; /** * Reset the one-shot LIFO starvation warning. Test-only: production code * should never need to call this. */ export declare function resetLifoStarvationWarningForTesting(): void; /** * Manages pending tasks and waiting long-poll requests. When a task is * enqueued and a matching waiter exists, the task is dispatched immediately. * When a poll request arrives and no task is available, the request blocks * until a task arrives or the timeout expires. * * `serve()` owns the live instance and exposes it as * {@link WeftServer.taskQueue} for inspection. Direct `handleRequest()` hosts * can construct an instance alongside a `WorkerRegistry` and inject both via * `HandlerOptions`. Prefer the `WeftServer` methods (`dispatchTask`, * `shutdownWorker`, etc.) over mutating a server-owned queue directly. * * @example * ```ts * import { serve, TaskQueue } from '@lostgradient/weft/server'; * import { Engine, MemoryStorage } from '@lostgradient/weft'; * * await using engine = new Engine({ storage: new MemoryStorage() }); * await using server = serve({ engine }); * * const taskQueue: TaskQueue = server.taskQueue; * const standaloneTaskQueue = new TaskQueue(); * void taskQueue; * standaloneTaskQueue[Symbol.dispose](); * ``` */ export declare class TaskQueue implements Disposable { #private; constructor(options?: TaskQueueOptions); /** The scheduling policy this queue was configured with. */ get schedulingPolicy(): SchedulingPolicy; /** * Enqueue a task. If a matching waiter exists, dispatch immediately. * Returns true if the task was dispatched to a waiter or queued. */ enqueue(queue: string, task: PendingTask, onComplete?: CompletionCallback): boolean; /** * Long-poll for a task. Returns immediately if a matching task is queued, * otherwise blocks until a task arrives or `timeout` milliseconds elapse. */ poll(queue: string, activities: string[], timeout: number, signal?: AbortSignal): Promise; /** * Report a task completion. Invokes the completion callback registered * during enqueue (if any). Returns true if a callback was found. */ complete(result: TaskResult): boolean; /** * Release all queue state on shutdown. Resolves every parked long-poll * waiter with `null` (so no poll promise is left unsettled), clears every * pending-task expiration timer, and drops all pending tasks, completion * callbacks, and dispatch tracking. * * Completion callbacks are intentionally NOT invoked: this is teardown, not * per-task expiration, and firing failure callbacks would push work into an * already-disposed engine/storage. Idempotent — safe to call more than once. */ [Symbol.dispose](): void; /** Check whether an operationId is currently tracked (pending or dispatched). */ isTracked(operationId: string): boolean; /** Check if any waiter in the queue can handle the given activity. */ hasWaiter(queue: string, activityName: string): boolean; /** Number of pending (unclaimed) tasks in a queue. */ pendingCount(queue: string): number; /** Total number of pending tasks across every queue. */ totalPendingCount(): number; /** Peek the ordered pending tasks for a queue without dequeuing. Test helper. */ peekPending(queue: string): PendingTask[]; /** * Synchronously reads internal state into a plain snapshot object for use by * {@link buildQueueSummaries}. Single-turn event-loop reads are consistent * without explicit locking. */ captureSnapshot(): TaskQueueSnapshot; /** * Per-queue summary used by `weft.task.queues.list`. Returns one entry per * queue appearing in `#pending` or `#waiters`, sorted ascending by name. * See {@link buildQueueSummaries} for field semantics. */ getQueueSummaries(): TaskQueueSummary[]; /** Remove and return pending tasks older than `maxAge` milliseconds. */ removeStale(maxAge: number): PendingTask[]; } export {};