/** * this is a wrapper for workers. we want to support node in addition to the * browser. bun seems to support web APIs with no modification, but node needs * special attention. not sure about deno. * * switching to specific classes for different environments. also the plan is * to add a main-thread (i.e. no-worker, inline calc) version. * */ export interface WorkerProxy { /** terminate worker */ Terminate: () => void; /** initialize, possibly loading code */ Init: (url: string, browser_init_method: () => Worker) => Promise; /** wrapper for postMessage */ PostMessage: (message: TX) => void; /** wrapper for addEventListener */ OnMessage: (fn: (message: MessageEvent) => void | Promise) => void; /** wrapper for addEventListener */ OnError: (fn: (message: ErrorEvent) => void | Promise) => void; } export declare class WorkerProxyBrowser implements WorkerProxy { worker?: Worker; Terminate(): void; /** * OK this changed to support svelte/vite/I guess it's all rollup under * the hood. whatever the tool is, it does static analysis and it has * to see the pattern loaded in order to bundle the worker module. so * we play ball. this is not a good situation. * * the browser init method should look something like this: * * () => { * return new Worker(new URL(url, import.meta.url), { * type: 'module' * }) as Worker; * } * * so that the code analyzer will see it. * * @param url * @param browser_init_method */ Init(url: string, browser_init_method: () => Worker): Promise; PostMessage(message: TX): void; OnMessage(fn: (message: MessageEvent) => (void | Promise)): void; OnError(fn: (message: ErrorEvent) => (void | Promise)): void; } export declare class WorkerProxyNode implements WorkerProxy { worker?: { postMessage: (message: TX) => void | Promise; terminate: () => void; on: (type: 'message' | 'error', handler: (data: RX) => void | Promise) => void; }; Terminate(): void; Init(url: string): Promise; PostMessage(message: TX): void; OnMessage(fn: (message: MessageEvent) => (void | Promise)): void; OnError(fn: (message: ErrorEvent) => (void | Promise)): void; } interface InProcessContext { addEventListener: (type: 'message', handler: (event: MessageEvent) => void | Promise) => void; postMessage: (data: RX) => void; } type composite = WorkerProxy & InProcessContext; export declare class WorkerProxyInProcess implements composite { protected tx_cache: TX[]; protected main_thread_to_worker_message_handler?: (event: MessageEvent) => void | Promise; protected rx_cache: RX[]; protected worker_to_main_thread_message_handler?: (message: MessageEvent) => void | Promise; Terminate(): void; Init(url: string): Promise; /** post message from "worker" to "main thread" */ PostMessage(message: TX): void; /** callback when "main thread" sends message to "worker" */ OnMessage(fn: (message: MessageEvent) => (void | Promise)): void; OnError(fn: (message: ErrorEvent) => (void | Promise)): void; FlushCache(cache: T[], fn: (message: MessageEvent) => void | Promise): void; addEventListener(type: 'message', handler: (event: MessageEvent) => void | Promise): void; postMessage(data: RX): void; } /** * factory method for workers. supports web workers (also bun), node workers * and (via parameter) in-process workers. we're still figuring out how to * signal that we're in process, currently somewhat clumsy * * @param in_process * @returns */ export declare function CreateWorker(in_process?: boolean): WorkerProxy; /** * this is for the worker side, to normalize postMessage/onmessage */ export declare const GetWorkerContext: () => Promise; export {};