UNPKG

task-farmer

Version:

A simple multi-core task scheduler that works well with promises. Great for doing parallel data processing.

26 lines (25 loc) 1.01 kB
import { IScheduler } from "./scheduler"; export declare type TaskFn<ResultT> = (...args: any[]) => Promise<ResultT>; export interface ITaskDef<ResultT> { getTaskName(): string; getTaskFn(): TaskFn<ResultT>; create(...inputs: any[]): ITask<ResultT>; } export interface ITask<ResultT> { getTaskId(): string; getTaskDef(): ITaskDef<ResultT>; run(scheduler: IScheduler): Promise<ResultT>; } export declare class Task<ResultT> implements ITask<ResultT> { static register<ResultT>(taskName: string, taskFn: TaskFn<ResultT>): ITaskDef<ResultT>; static lookup<ResultT>(taskDefId: string): ITaskDef<ResultT>; static all<ResultT>(inputTasks: ITask<ResultT>[]): ITask<ResultT[]>; private static taskDefs; private taskId; private inputTasks; private taskDef; constructor(inputTasks: ITask<any>[], taskDef: ITaskDef<ResultT>); getTaskId(): string; getTaskDef(): ITaskDef<ResultT>; run(scheduler: IScheduler): Promise<ResultT>; }