import { ImageInfo } from "../ImageInfo.js"; import { VolumeDims } from "../VolumeDims.js"; import { CreateLoaderOptions, PrefetchDirection } from "../loaders/index.js"; import { ThreadableVolumeLoader, LoadSpec, RawChannelDataCallback, LoadedVolumeInfo } from "../loaders/IVolumeLoader.js"; import { RawArrayLoader } from "../loaders/RawArrayLoader.js"; import { TiffLoader } from "../loaders/TiffLoader.js"; import type { WorkerRequestPayload, WorkerResponsePayload, ChannelLoadEvent, MetadataUpdateEvent } from "./types.js"; import type { ZarrLoaderFetchOptions } from "../loaders/OmeZarrLoader.js"; import { WorkerMsgType } from "./types.js"; /** * A handle that holds the worker and manages requests and messages to/from it. * * `VolumeLoaderContext` and every `LoaderWorker` it creates all hold references to one `SharedLoadWorkerHandle`. * They use it to interact with the worker via `sendMessage`, which speaks the protocol defined in ./types.ts and * converts messages received from the worker into resolved `Promise`s and called callbacks. * * This class exists to represent that access to the worker is shared between `VolumeLoaderContext` and any * `LoaderWorker`s. This is as opposed to implementing `sendMessage` directly on `VolumeLoaderContext`, where making * the method public to `LoaderWorker`s would require also allowing access to users of the class. */ declare class SharedLoadWorkerHandle { private worker; private pendingRequests; private workerOpen; private throttleChannelData; onChannelData: ((e: ChannelLoadEvent) => void) | undefined; onUpdateMetadata: ((e: MetadataUpdateEvent) => void) | undefined; constructor(); /** Given a handle for settling a promise when a response is received from the worker, store it and return its ID */ private registerMessagePromise; get isOpen(): boolean; /** Close the worker. */ close(): void; /** * Send a message of type `T` to the worker. * Returns a `Promise` that resolves with the worker's response, or rejects with an error message. */ sendMessage(type: T, payload: WorkerRequestPayload): Promise>; /** Receive a message from the worker. If it's an event, call a callback; otherwise, resolve/reject a promise. */ private receiveMessage; setThrottleChannelData(throttle: boolean): void; } /** * A context in which volume loaders can be run, which allows loading to run on a WebWorker (where it won't block * rendering or UI updates) and loaders to share a single `VolumeCache` and `RequestQueue`. * * ### To use: * 1. Create a `VolumeLoaderContext` with the desired cache and queue configuration. * 2. Before creating a loader, await `onOpen` to ensure the worker is ready. * 3. Create a loader with `createLoader`. This accepts nearly the same arguments as `createVolumeLoader`, but without * options to directly link to a cache or queue (the loader will always be linked to the context's shared instances * of these if possible). * * The returned `WorkerLoader` can be used like any other `IVolumeLoader` and acts as a handle to the actual loader * running on the worker. */ declare class VolumeLoaderContext { private workerHandle; private openPromise; private activeLoader; private activeLoaderId; constructor(maxCacheSize?: number, maxActiveRequests?: number, maxLowPriorityRequests?: number); /** Returns a `Promise` that resolves when the worker is ready. `await` it before trying to create a loader. */ onOpen(): Promise; /** Close this context, its worker, and any active loaders. */ close(): void; /** * Create a new loader within this context. This loader will share the context's `VolumeCache` and `RequestQueue`. * * This works just like `createVolumeLoader`. A file format may be provided, or it may be inferred from the URL. */ createLoader(path: string | string[], options?: Omit): Promise; setThrottleChannelData(throttle: boolean): void; getActiveLoader(): WorkerLoader | undefined; } /** * A handle to an instance of `IVolumeLoader` (technically, a `ThreadableVolumeLoader`) running on a WebWorker. * * Created with `VolumeLoaderContext.createLoader`. See its documentation for more. */ declare class WorkerLoader extends ThreadableVolumeLoader { private loaderId; private workerHandle; private isOpen; private currentLoadId; private currentLoadCallback; private currentMetadataUpdateCallback; constructor(loaderId: number, workerHandle: SharedLoadWorkerHandle); private checkIsOpen; /** Close and permanently invalidate this loader. */ close(): void; /** * Change which directions to prioritize when prefetching. All chunks will be prefetched in these directions before * any chunks are prefetched in any other directions. Has no effect if this loader doesn't support prefetching. */ setPrefetchPriority(directions: PrefetchDirection[]): Promise; updateFetchOptions(fetchOptions: Partial): Promise; syncMultichannelLoading(sync: boolean): Promise; loadDims(loadSpec: LoadSpec): Promise; createImageInfo(loadSpec: LoadSpec): Promise; loadRawChannelData(imageInfo: ImageInfo, loadSpec: LoadSpec, onUpdateMetadata: (imageInfo?: ImageInfo, loadSpec?: LoadSpec) => void, onData: RawChannelDataCallback): Promise; onChannelData(e: ChannelLoadEvent): void; onUpdateMetadata(e: MetadataUpdateEvent): void; } export default VolumeLoaderContext; export type { WorkerLoader };