import { EntryPointArguments } from './workers-factory'; /** * Trait for abstracting the concept of Web Worker; default implementation is based on * the WebWorker API provided by the browser, see {@link WebWorkerBrowser}. */ export interface WWorkerTrait { /** * Worker's UID */ uid: string; /** * * @param params.taskId task Id * @param params.entryPoint function to execute * @param params.args arguments to provide to the function * */ execute(params: { taskId: string; entryPoint: (args: EntryPointArguments) => unknown; args: T; }): any; /** * Send to the worker some data in the channel associated to `taskId` * @param params.taskId task Id * @param params.data arguments to send */ send(params: { taskId: string; data: T; }): any; terminate(): any; } export type InWorkerAction = ({ message, workerScope }: { message: any; workerScope: any; }) => void; /** * Proxy for WebWorkers creation. * * The default implementation used is the one provided by the browser ({@link WebWorkersBrowser}). * Can be also overriden for example for testing contexts. */ export interface IWWorkerProxy { type: string; createWorker({ onMessageWorker, onMessageMain, }: { onMessageWorker: (message: any) => unknown; onMessageMain: (message: any) => unknown; }): WWorkerTrait; serializeFunction(fct?: (...unknown: any[]) => unknown): any; onBeforeWorkerInstall?: InWorkerAction; onAfterWorkerInstall?: InWorkerAction; } /** * Implementation of {@link WWorkerTrait} for Web Workers provided by browsers. */ export declare class WebWorkerBrowser implements WWorkerTrait { /** * Immutable Constants */ readonly uid: string; /** * Immutable Constants */ readonly worker: Worker; constructor(params: { uid: string; worker: Worker; }); execute({ taskId, entryPoint, args }: { taskId: any; entryPoint: any; args: any; }): void; send({ taskId, data }: { taskId: string; data: T; }): void; terminate(): void; } export declare class WebWorkersBrowser implements IWWorkerProxy { type: string; createWorker({ onMessageWorker, onMessageMain, }: { onMessageWorker: (message: any) => unknown; onMessageMain: (message: any) => unknown; }): WebWorkerBrowser; serializeFunction(fct?: (...unknown: any[]) => unknown): string; }