@beenotung/tslib
Version:
utils library in Typescript
32 lines (31 loc) • 892 B
TypeScript
import { ChildProcess } from 'child_process';
export type WeightedProcessWorker = {
weight: number;
process: ChildProcess;
};
/**
* dispatcher of workers created from `child_process.fork`
*
* only support request-response batch-by-batch
* DO NOT support multiple interlaced concurrent batches
* */
export declare class ProcessPool {
totalWeights: number;
workers: WeightedProcessWorker[];
dispatch: {
<T, R>(inputs: T[], cb: (err: any, outputs: R[]) => void): void;
<T, R>(inputs: T[]): Promise<R[]>;
};
constructor(options: {
modulePath: string;
weights?: number[];
/**
* number of worker = (number of core / weights) * overload
* default to 1.0
* */
overload?: number;
} | {
workers: WeightedProcessWorker[];
});
close(signal?: NodeJS.Signals | number): void;
}