parallel-es
Version:
Simple parallelization for EcmaScript
48 lines (47 loc) • 1.87 kB
TypeScript
import { ITaskDefinition } from "../task/task-definition";
import { IWorkerThread } from "./worker-thread";
import { DynamicFunctionRegistry } from "../function/dynamic-function-registry";
import { WorkerThreadState } from "./worker-thread-state";
import { IWorkerThreadSlaveCommunicationChannel } from "./worker-thread-slave-communication-channel";
/**
* Worker Thread Endpoint in the UI-Thread.
* Implements the communication with the {@link IWorkerSlave} in the worker thread.
*/
export declare class DefaultWorkerThread implements IWorkerThread {
private functionLookupTable;
private communicationChannel;
/**
* Unique id of this worker thread
*/
id: number;
/**
* The current state of the worker thread
*/
state: WorkerThreadState;
private stopped;
/**
* Creates a new instance that communicates with the given worker
* @param communicationChannel the {@link IWorkerThreadSlaveCommunicationChannel} to the slave
* @param functionLookupTable
*/
constructor(functionLookupTable: DynamicFunctionRegistry, communicationChannel: IWorkerThreadSlaveCommunicationChannel);
/**
* Assigns a unique id to the worker
* Can only be invoked once. Must be invoked before any task is scheduled.
*/
initialize(): void;
/**
* Executes the given task on the worker.
* Requires that the worker thread has been initialized
* @param task the task to execute
* @param callback the callback to invoke when the task has completed (successful or not)
*/
run(task: ITaskDefinition, callback: (error: any, result: any) => void): void;
/**
* Stops the worker as soon as it receives the message. Does not wait to complete the task.
*/
stop(): void;
toString(): string;
private onWorkerMessage(message);
private onError(event);
}