diff --git a/types/workerpool/index.d.ts b/types/workerpool/index.d.ts index c8a128203b..2bb6ca4b66 100644 --- a/types/workerpool/index.d.ts +++ b/types/workerpool/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for workerpool 3.1 +// Type definitions for workerpool 5.0 // Project: https://github.com/josdejong/workerpool // Definitions by: Alorel // Seulgi Kim @@ -96,9 +96,21 @@ export interface WorkerPoolOptions { * In case of 'process' (default), child_process will be used. * In case of 'thread', worker_threads will be used. If worker_threads are not available, an error is thrown. * In case of 'auto', worker_threads will be used if available (Node.js >= 11.7.0), else child_process will be used as fallback. + * @deprecated */ nodeWorker?: 'process' | 'thread' | 'auto'; + /** + * - In case of `'auto'` (default), workerpool will automatically pick a suitable type of worker: + * when in a browser environment, `'web'` will be used. When in a node.js environment, `worker_threads` will be used + * if available (Node.js >= 11.7.0), else `child_process` will be used. + * - In case of `'web'`, a Web Worker will be used. Only available in a browser environment. + * - In case of `'process'`, `child_process` will be used. Only available in a node.js environment. + * - In case of `'thread'`, `worker_threads` will be used. If `worker_threads` are not available, an error is thrown. + * Only available in a node.js environment. + */ + workerType?: 'auto' | 'web' | 'process' | 'thread'; + /** 2nd argument to pass to childProcess.fork() */ forkArgs?: string[]; @@ -106,9 +118,11 @@ export interface WorkerPoolOptions { } /** - * When a script argument is provided, the provided script will be started as a dedicated worker. - * When no script argument is provided, a default worker is started which can be used to offload functions dynamically via Pool.exec. - * Note that on node.js, script must be an absolute file path like __dirname + '/myWorker.js'. + * When a `script` argument is provided, the provided script will be started as a dedicated worker. + * When no `script` argument is provided, a default worker is started which can be used to offload functions dynamically via `Pool.exec`. + * Note that on node.js, `script` must be an absolute file path like `__dirname + '/myWorker.js'`. + * In a browser environment, `script` can also be a data URL like `'data:application/javascript;base64,...'`. + * This allows embedding the bundled code of a worker in your main application. See `examples/embeddedWorker` for a demo. */ export function pool(pathToScript?: string, options?: WorkerPoolOptions): WorkerPool; diff --git a/types/workerpool/workerpool-tests.ts b/types/workerpool/workerpool-tests.ts index dc75955479..b1d3c38c4d 100644 --- a/types/workerpool/workerpool-tests.ts +++ b/types/workerpool/workerpool-tests.ts @@ -9,6 +9,10 @@ wp.pool({maxWorkers: 1}); wp.pool({nodeWorker: 'process'}); wp.pool({nodeWorker: 'thread'}); wp.pool({nodeWorker: 'auto'}); +wp.pool({workerType: 'process'}); +wp.pool({workerType: 'thread'}); +wp.pool({workerType: 'web'}); +wp.pool({workerType: 'auto'}); wp.pool({forkArgs: ['foo', 'bar']}); wp.pool({forkOpts: {cwd: '/tmp'}}); const pool = wp.pool();