parallel-es
Version:
Simple parallelization for EcmaScript
34 lines (33 loc) • 1.53 kB
TypeScript
import { IThreadPool } from "./thread-pool";
import { ITaskDefinition } from "../task/task-definition";
import { IWorkerThreadFactory } from "../worker/worker-thread-factory";
import { ITask } from "../task/task";
/**
* Default thread pool implementation that processes the scheduled functions in FIFO order.
*/
export declare class DefaultThreadPool implements IThreadPool {
private workerThreadFactory;
private workers;
private idleWorkers;
private queue;
private maxThreadsLimit;
maxThreads: number;
constructor(workerThreadFactory: IWorkerThreadFactory, options: {
maxConcurrencyLevel: number;
});
run<TResult>(taskDefinition: ITaskDefinition): ITask<TResult>;
/**
* Schedules the tasks in the queue onto the available workers.
* A new worker is spawned when no more idle workers are available and the number of workers has not yet reached the concurrency limit.
* If no more idle workers are available and the concurrency limit has been reached then the tasks are left in queue.
*/
private schedulePendingTasks();
/**
* Starts the given task on the given worker. Resolves the task when the computation succeeds, rejects it otherwise.
* The task is resolved when the computation has succeeded or is rejected if the computation failed
* @param task the task to run on the given worker
* @param worker the worker to use to execute the task
*/
private runTaskOnWorker(task, worker);
private releaseWorker(worker);
}