web-worker-helper
Version:
Utilities for running tasks on worker threads
47 lines (46 loc) • 1.49 kB
TypeScript
import WorkerPool from './worker-pool';
export type WorkerFarmProps = {
maxConcurrency?: number;
maxMobileConcurrency?: number;
reuseWorkers?: boolean;
onDebug?: () => void;
};
/**
* Process multiple jobs with a "farm" of different workers in worker pools.
*/
export default class WorkerFarm {
private props;
private workerPools;
private static workerFarm?;
/** Check if Workers are supported */
static isSupported(): boolean;
/** Get the singleton instance of the global worker farm */
static getWorkerFarm(props?: WorkerFarmProps): WorkerFarm;
/** get global instance with WorkerFarm.getWorkerFarm() */
constructor(props: WorkerFarmProps);
/**
* Terminate all workers in the farm
* @note Can free up significant memory
*/
destroy(): void;
/**
* Set props used when initializing worker pools
* @param props
*/
setProps(props: WorkerFarmProps): void;
/**
* Returns a worker pool for the specified worker
* @param options - only used first time for a specific worker name
* @param options.name - the name of the worker - used to identify worker pool
* @param options.url -
* @param options.source -
* @example
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
*/
getWorkerPool(options: {
name: string;
source?: string;
url?: string;
}): WorkerPool;
private getWorkerPoolProps;
}