import { type Context } from '@dxos/context'; export type UpdateSchedulerOptions = { /** * Maximum frequency of updates. If not specified, updates will be scheduled on every change. */ maxFrequency?: number; }; /** * Runs a non-reentrant callback at most once at a time, coalescing triggers (optionally rate-limited * via {@link UpdateSchedulerOptions.maxFrequency}). * * The runner inside {@link trigger} is the only place the callback starts; `runBlocking` and * `forceTrigger` funnel into it. That, plus `_scheduled` collapsing triggers into one pending * runner, is what makes mutual exclusion hold by construction (dxos/edge#758). */ export declare class UpdateScheduler { private readonly _ctx; private readonly _callback; private readonly _params; /** The running pass; never rejects, non-null exactly while a run is executing. */ private _currentTask; private _scheduled; /** * Armed by the `trigger` that schedules a runner, woken by that runner when it claims — with the * run's promise, which `Trigger` adopts, so waiters resume when the run *finishes*. Lets * `runBlocking` await a run that does not exist in `_currentTask` yet. * * `reset()` abandons parked waiters, so it may only be armed in `trigger`'s non-coalesced branch: * waiters park only while `_scheduled` is true, and that branch requires it false. */ private _runOutcome; /** Woken to make the pending runner skip its throttle delay. Replaced at claim time. */ private _skipDelay; /** * `runBlocking` callers in flight, incremented synchronously before triggering. A failing run uses * it to tell whether someone will throw the error; counting microtask hops to a waiter's resume * would be a race. */ private _observers; private _lastUpdateTime; constructor(_ctx: Context, _callback: () => Promise, _params?: UpdateSchedulerOptions); get scheduled(): boolean; /** * Schedule the callback to run asynchronously. Triggers issued while a run is pending or in flight * coalesce into the next run. */ trigger(): void; /** * Run as soon as possible: schedules (coalescing with any pending run) and skips the throttle * delay. Does not start a concurrent callback. */ forceTrigger(): void; /** * Waits for the current task to finish if it is running. * Does not schedule a new task, and does not wait for one that is merely scheduled. */ join(): Promise; /** * Ensure a run that observes everything enqueued so far, and wait for it to finish. Waits for the * pending run to claim, then for its result; that run necessarily claims after this call, so its * drain includes everything enqueued before it. Rejects with the run's error so a flush barrier can * see its batch was not handed off. No-op once disposed. */ runBlocking(): Promise; } //# sourceMappingURL=update-scheduler.d.ts.map