1 | /// <reference types="node" />
|
---|
2 | import { Worker, MessagePort } from 'worker_threads';
|
---|
3 | import EventEmitterAsyncResource from 'eventemitter-asyncresource';
|
---|
4 | import { Transferable, TaskQueue } from './common';
|
---|
5 | interface AbortSignalEventTargetAddOptions {
|
---|
6 | once: boolean;
|
---|
7 | }
|
---|
8 | interface AbortSignalEventTarget {
|
---|
9 | addEventListener: (name: 'abort', listener: () => void, options?: AbortSignalEventTargetAddOptions) => void;
|
---|
10 | removeEventListener: (name: 'abort', listener: () => void) => void;
|
---|
11 | aborted?: boolean;
|
---|
12 | }
|
---|
13 | interface AbortSignalEventEmitter {
|
---|
14 | off: (name: 'abort', listener: () => void) => void;
|
---|
15 | once: (name: 'abort', listener: () => void) => void;
|
---|
16 | }
|
---|
17 | declare type AbortSignalAny = AbortSignalEventTarget | AbortSignalEventEmitter;
|
---|
18 | declare type ResourceLimits = Worker extends {
|
---|
19 | resourceLimits?: infer T;
|
---|
20 | } ? T : {};
|
---|
21 | declare type EnvSpecifier = typeof Worker extends {
|
---|
22 | new (filename: never, options?: {
|
---|
23 | env: infer T;
|
---|
24 | }): Worker;
|
---|
25 | } ? T : never;
|
---|
26 | interface Options {
|
---|
27 | filename?: string | null;
|
---|
28 | name?: string;
|
---|
29 | minThreads?: number;
|
---|
30 | maxThreads?: number;
|
---|
31 | idleTimeout?: number;
|
---|
32 | maxQueue?: number | 'auto';
|
---|
33 | concurrentTasksPerWorker?: number;
|
---|
34 | useAtomics?: boolean;
|
---|
35 | resourceLimits?: ResourceLimits;
|
---|
36 | argv?: string[];
|
---|
37 | execArgv?: string[];
|
---|
38 | env?: EnvSpecifier;
|
---|
39 | workerData?: any;
|
---|
40 | taskQueue?: TaskQueue;
|
---|
41 | niceIncrement?: number;
|
---|
42 | trackUnmanagedFds?: boolean;
|
---|
43 | }
|
---|
44 | interface FilledOptions extends Options {
|
---|
45 | filename: string | null;
|
---|
46 | name: string;
|
---|
47 | minThreads: number;
|
---|
48 | maxThreads: number;
|
---|
49 | idleTimeout: number;
|
---|
50 | maxQueue: number;
|
---|
51 | concurrentTasksPerWorker: number;
|
---|
52 | useAtomics: boolean;
|
---|
53 | taskQueue: TaskQueue;
|
---|
54 | niceIncrement: number;
|
---|
55 | }
|
---|
56 | interface RunOptions {
|
---|
57 | transferList?: TransferList;
|
---|
58 | filename?: string | null;
|
---|
59 | signal?: AbortSignalAny | null;
|
---|
60 | name?: string | null;
|
---|
61 | }
|
---|
62 | declare type TransferList = MessagePort extends {
|
---|
63 | postMessage(value: any, transferList: infer T): any;
|
---|
64 | } ? T : never;
|
---|
65 | declare type TransferListItem = TransferList extends (infer T)[] ? T : never;
|
---|
66 | declare class Piscina extends EventEmitterAsyncResource {
|
---|
67 | #private;
|
---|
68 | constructor(options?: Options);
|
---|
69 | /** @deprecated Use run(task, options) instead **/
|
---|
70 | runTask(task: any, transferList?: TransferList, filename?: string, abortSignal?: AbortSignalAny): Promise<any>;
|
---|
71 | /** @deprecated Use run(task, options) instead **/
|
---|
72 | runTask(task: any, transferList?: TransferList, filename?: AbortSignalAny, abortSignal?: undefined): Promise<any>;
|
---|
73 | /** @deprecated Use run(task, options) instead **/
|
---|
74 | runTask(task: any, transferList?: string, filename?: AbortSignalAny, abortSignal?: undefined): Promise<any>;
|
---|
75 | /** @deprecated Use run(task, options) instead **/
|
---|
76 | runTask(task: any, transferList?: AbortSignalAny, filename?: undefined, abortSignal?: undefined): Promise<any>;
|
---|
77 | run(task: any, options?: RunOptions): Promise<any>;
|
---|
78 | destroy(): Promise<void>;
|
---|
79 | get options(): FilledOptions;
|
---|
80 | get threads(): Worker[];
|
---|
81 | get queueSize(): number;
|
---|
82 | get completed(): number;
|
---|
83 | get waitTime(): any;
|
---|
84 | get runTime(): any;
|
---|
85 | get utilization(): number;
|
---|
86 | get duration(): number;
|
---|
87 | static get isWorkerThread(): boolean;
|
---|
88 | static get workerData(): any;
|
---|
89 | static get version(): string;
|
---|
90 | static get Piscina(): typeof Piscina;
|
---|
91 | static move(val: Transferable | TransferListItem | ArrayBufferView | ArrayBuffer | MessagePort): ArrayBuffer | ArrayBufferView | MessagePort | Transferable;
|
---|
92 | static get transferableSymbol(): symbol;
|
---|
93 | static get valueSymbol(): symbol;
|
---|
94 | static get queueOptionsSymbol(): symbol;
|
---|
95 | }
|
---|
96 | export = Piscina;
|
---|