concurrent-worker
Version:
Multithreading for javascript
26 lines (25 loc) • 1.73 kB
TypeScript
import { IWorker, IWorkerConfig, IWorkerContext, ThenArg, WorkerThis } from "./types";
/**
* Call worker with given arguments, returns a promise that resolves when onmessage is called
* with matching syncId.
*/
export declare const executePromiseWorker: <T extends unknown[], R>(worker: Worker, syncId: number, args: T, transferrable?: Transferable[]) => Promise<ThenArg<R>>;
/**
* Creates a task that can be run in a webworker. If you want to use functions and variables from
* the outer scope you must pass them in via the context parameter, else they will not be available.
* This creation method creates a new web worker for each call to it allowing multiple calls to run in paralel.
*
* @param task Function to execute off the main thread
* @param config Worker configuration
*/
export declare const concurrent: <T extends unknown[], C extends IWorkerContext, R>(task: string | ((this: WorkerThis<C>, ...args: T) => R), config?: IWorkerConfig<T, C, R>) => IWorker<T, C, R>;
/**
* Creates a task that can be run in a webworker. If you want to use functions and variables from
* the outer scope you must pass them in via the context parameter, else they will not be available.
* This creation method uses a single web worker for all calls to it, calls will be processed synchronously
* in that worker. Has les overhead than `create` but does not run multiple calls in paralel.
*
* @param task Function to execute off the main thread, or object url pointing to worker script
* @param config Worker configuration
*/
export declare const serial: <T extends unknown[], C extends IWorkerContext, R>(task: string | ((this: WorkerThis<C>, ...args: T) => R), config?: IWorkerConfig<T, C, R>) => IWorker<T, C, R>;