/** * Render scheduling and cancellation. * * The worker is single-threaded: a `renderPage` command posted to it runs to * completion and cannot be interrupted. Posting every render immediately * therefore builds a queue *inside* the worker that nothing can reach — scroll * quickly through a long document and the pages now on screen wait behind a * backlog of pages that scrolled away long ago. * * So the queue is kept here instead. One render is handed to the worker at a * time and the rest wait where they can still be dropped. This mirrors pdfrx's * `PdfPageRenderCancellationToken`, which likewise cancels work that has not * started rather than aborting a render already in progress. */ /** * Cancels a {@link PdfPage.render} that has not started yet. * * Create one with {@link PdfPage.createCancellationToken} and pass it as * {@link PdfPageRenderOptions.cancellationToken}. Cancelling makes `render` * resolve to `null`. A render already running in the worker cannot be * interrupted — it finishes, and its result is discarded. * * A token belongs to a single render; create a new one per call. * * @example * ```ts * const token = page.createCancellationToken(); * const image = await page.render({ fullWidth, fullHeight, cancellationToken: token }); * if (!image) return; // cancelled (or the document was disposed) * ``` */ export declare class PdfPageRenderCancellationToken { private canceled; private onCancel; /** Whether {@link cancel} has been called. */ get isCanceled(): boolean; /** * Cancels the render. If it is still queued it never runs and `render` * resolves to `null`; if the worker already started it, the result is * discarded when it arrives. Idempotent. */ cancel(): void; /** @internal Registers the queue's drop hook (fires immediately if already cancelled). */ attach(onCancel: () => void): void; /** @internal Detaches the drop hook once the work is no longer droppable. */ detach(): void; } /** * @internal * Serializes render commands so that queued work stays cancellable. Owned by * {@link WorkerCommunicator} — one queue per worker, shared by every document * it opened, because the worker is what is actually being contended for. * * Exactly one render is outstanding at a time. Posting a second one early * would not make the worker any faster — it renders serially regardless — it * would only move that render into the worker's queue, out of reach of * cancellation, which is the opposite of the point. */ export declare class RenderQueue { private readonly queue; private active; private disposed; /** Number of renders waiting for a slot (excludes those already dispatched). */ get pending(): number; /** * Queues `run`, resolving with its result — or with `null` if `token` was * cancelled before the result was in hand. */ enqueue(run: () => Promise, token?: PdfPageRenderCancellationToken): Promise; private pump; /** Drops everything still queued; dispatched renders are left to settle. */ clear(): void; /** Drops queued work and refuses any more. */ dispose(): void; } //# sourceMappingURL=render-queue.d.ts.map