import type { BatchOperation, Storage } from '../../storage/interface.ts'; import type { TimerEntry } from '../types.ts'; export interface SchedulerOptions { storage: Storage; onTimerFired: (entry: TimerEntry) => void | Promise; pollIntervalMs?: number; getNow?: () => number; /** * Commit the batch that deletes a fired timer's keys after its callback * returns. Defaults to an unfenced `storage.batch`. The engine supplies a * lease-fenced commit (#563) so the fired-timer delete and the callback's own * follow-up writes share the same ownership fence — under deposition both are * rejected and the timer survives for the successor to re-drive. With no lease * held this commits exactly as the unfenced default would. */ commitTimerCleanup?: (operations: BatchOperation[]) => Promise; } /** * Scheduler manages durable timers and polls for expired deadlines. * * @example * ```ts * import { Scheduler } from '@lostgradient/weft'; * import { MemoryStorage } from '@lostgradient/weft/storage/memory'; * * const storage = new MemoryStorage(); * const scheduler = new Scheduler({ * storage, * onTimerFired: (entry) => { * console.log('timer fired:', entry.id, entry.kind); * }, * pollIntervalMs: 500, * }); * * scheduler.start(); * // ... use scheduler ... * scheduler.stop(); * ``` */ export declare class Scheduler implements Disposable { #private; constructor(options: SchedulerOptions); /** Start the polling loop. */ start(): void; /** Stop the polling loop. */ stop(): void; /** Schedule a durable timer (writes to storage). */ schedule(entry: TimerEntry): Promise; /** Cancel a timer (removes from storage). */ cancel(id: string, _workflowId: string): Promise; /** Force an immediate scan for expired timers (for tests). */ tick(now?: number): Promise; /** Process all expired timers then stop. * Works even after stop() has been called — the intent is to drain remaining * timers before final shutdown. Bypasses the #stopped guard so a * stop()-then-flush() sequence works without re-enabling suspended interval * ticks that might race with this drain. */ flush(now?: number): Promise; [Symbol.dispose](): void; }