1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import type { EventEmitter } from 'events';
|
9 | import type { ForkOptions } from 'child_process';
|
10 | export declare const CHILD_MESSAGE_INITIALIZE: 0;
|
11 | export declare const CHILD_MESSAGE_CALL: 1;
|
12 | export declare const CHILD_MESSAGE_END: 2;
|
13 | export declare const PARENT_MESSAGE_OK: 0;
|
14 | export declare const PARENT_MESSAGE_CLIENT_ERROR: 1;
|
15 | export declare const PARENT_MESSAGE_SETUP_ERROR: 2;
|
16 | export declare type PARENT_MESSAGE_ERROR = typeof PARENT_MESSAGE_CLIENT_ERROR | typeof PARENT_MESSAGE_SETUP_ERROR;
|
17 | export interface WorkerPoolInterface {
|
18 | getStderr(): NodeJS.ReadableStream;
|
19 | getStdout(): NodeJS.ReadableStream;
|
20 | getWorkers(): Array<WorkerInterface>;
|
21 | createWorker(options: WorkerOptions): WorkerInterface;
|
22 | send(workerId: number, request: ChildMessage, onStart: OnStart, onEnd: OnEnd): void;
|
23 | end(): Promise<PoolExitResult>;
|
24 | }
|
25 | export interface WorkerInterface {
|
26 | send(request: ChildMessage, onProcessStart: OnStart, onProcessEnd: OnEnd): void;
|
27 | waitForExit(): Promise<void>;
|
28 | forceExit(): void;
|
29 | getWorkerId(): number;
|
30 | getStderr(): NodeJS.ReadableStream | null;
|
31 | getStdout(): NodeJS.ReadableStream | null;
|
32 | }
|
33 | export declare type PoolExitResult = {
|
34 | forceExited: boolean;
|
35 | };
|
36 | export type { ForkOptions };
|
37 | export declare type FarmOptions = {
|
38 | computeWorkerKey?: (method: string, ...args: Array<unknown>) => string | null;
|
39 | exposedMethods?: ReadonlyArray<string>;
|
40 | forkOptions?: ForkOptions;
|
41 | setupArgs?: Array<unknown>;
|
42 | maxRetries?: number;
|
43 | numWorkers?: number;
|
44 | WorkerPool?: (workerPath: string, options?: WorkerPoolOptions) => WorkerPoolInterface;
|
45 | enableWorkerThreads?: boolean;
|
46 | };
|
47 | export declare type WorkerPoolOptions = {
|
48 | setupArgs: Array<unknown>;
|
49 | forkOptions: ForkOptions;
|
50 | maxRetries: number;
|
51 | numWorkers: number;
|
52 | enableWorkerThreads: boolean;
|
53 | };
|
54 | export declare type WorkerOptions = {
|
55 | forkOptions: ForkOptions;
|
56 | setupArgs: Array<unknown>;
|
57 | maxRetries: number;
|
58 | workerId: number;
|
59 | workerPath: string;
|
60 | };
|
61 | export declare type MessagePort = typeof EventEmitter & {
|
62 | postMessage(message: unknown): void;
|
63 | };
|
64 | export declare type MessageChannel = {
|
65 | port1: MessagePort;
|
66 | port2: MessagePort;
|
67 | };
|
68 | export declare type ChildMessageInitialize = [typeof CHILD_MESSAGE_INITIALIZE,
|
69 | boolean,
|
70 | string,
|
71 |
|
72 | Array<unknown> | undefined,
|
73 |
|
74 | MessagePort | undefined];
|
75 | export declare type ChildMessageCall = [typeof CHILD_MESSAGE_CALL,
|
76 | boolean,
|
77 | string,
|
78 | Array<unknown>];
|
79 | export declare type ChildMessageEnd = [typeof CHILD_MESSAGE_END,
|
80 | boolean];
|
81 | export declare type ChildMessage = ChildMessageInitialize | ChildMessageCall | ChildMessageEnd;
|
82 | export declare type ParentMessageOk = [typeof PARENT_MESSAGE_OK,
|
83 | unknown];
|
84 | export declare type ParentMessageError = [PARENT_MESSAGE_ERROR,
|
85 | string,
|
86 | string,
|
87 | string,
|
88 | unknown];
|
89 | export declare type ParentMessage = ParentMessageOk | ParentMessageError;
|
90 | export declare type OnStart = (worker: WorkerInterface) => void;
|
91 | export declare type OnEnd = (err: Error | null, result: unknown) => void;
|
92 | export declare type QueueChildMessage = {
|
93 | request: ChildMessage;
|
94 | onStart: OnStart;
|
95 | onEnd: OnEnd;
|
96 | };
|
97 | export declare type QueueItem = {
|
98 | task: QueueChildMessage;
|
99 | next: QueueItem | null;
|
100 | };
|