///
import { Worker as Thread } from 'worker_threads';
import { Task } from './task';
export declare enum WorkerState {
STARTING = 0,
FREE = 1,
RESERVED = 2,
WORKING = 3,
EXHAUSTED = 4
}
export interface WorkerSpawnData {
queueName: string;
}
export interface WorkerOptions {
queueName: string;
entry: string;
}
/**
* Messages sent from main thread
*/
export declare enum ParentMessageTypes {
START_TASK = "START_TASK"
}
/**
* Message interface from main thread
*/
export interface ParentMessage {
type: ParentMessageTypes;
data?: any;
}
export declare class Worker {
state: WorkerState;
protected thread: Thread;
protected id: number;
protected task: Task;
/**
* Spawn a thread for this worker
*
* Runs on: Main
*
* @param options Worker options
* @returns Returns the worker
*/
spawn(options: WorkerOptions): Promise>;
/**
* Push a task to the worker
*
* Runs on: Main
*
* @param task Task to push
*/
startTask(task: Task): void;
/**
* Runs when the worker completes a task
*
* Runs on: Main
*
* @param response Response from the worker for this task
*/
protected finished(response?: TOut): void;
/**
* Runs when the worker fails to complete a task
*
* Runs on: Main
*
* @param error Response from the worker
*/
protected failed(error?: Error): void;
/**
* Runs when the worker errors or exits unexpectedly
*
* Runs on: Main
*
* @param error Error returned by the worker
*/
protected exhausted(error?: Error): void;
}