/** * src/core/ConcurrencyQueue.ts * * Priority queue manager for the Society. Ensures work is prioritised, slots * are respected, and no request starves. * * Implements docs/architecture/concurrency-and-queues.md: * - Priority levels: USER (2), SCHEDULED (1), BACKGROUND (0) * - Configurable slots (default 3, max 10) * - Queue depth cap = 10× slots * - Starvation escalation at 60s * - USER-displacement when queue is full */ export type Priority = 'USER' | 'SCHEDULED' | 'BACKGROUND'; export interface QueuedTask { id: string; label: string; priority: Priority; priorityValue: number; enqueuedAt: number; execute: () => Promise; } export interface QueueStatus { running: number; queued: number; paused: number; slotsTotal: number; } export declare class ConcurrencyQueue { private queue; private running; private paused; private slotCount; private readonly maxDepth; private readonly starvationMs; private timerId; constructor(slots?: number, starvationMs?: number); /** * Enqueue a task for execution. Returns true if the task was accepted, * false if it was rejected (BACKGROUND when queue full). * * Throws if the queue is full and the request cannot be admitted even * via displacement. */ enqueue(task: QueuedTask): boolean; /** Process the next task if a slot is available. */ private tryProcess; private execute; /** * Displace the lowest-priority item from the queue to make room for * a USER request. */ private displaceLowestPriority; /** * Starvation prevention: boost priority of tasks that have been waiting * longer than the threshold. Call periodically or automatically. */ private checkStarvation; /** Start the starvation checker background timer. */ start(): void; /** Stop the starvation checker. */ stop(): void; getStatus(): QueueStatus; statusLine(): string; } //# sourceMappingURL=ConcurrencyQueue.d.ts.map