update workerpool to v5 (#38382)

* update workerpool to v5

* follow tslint

* update function pool doc
This commit is contained in:
Takashi Tamura
2019-09-27 09:03:37 +09:00
committed by Ben Lichtman
parent 6aad817004
commit f161e550b4
2 changed files with 22 additions and 4 deletions

View File

@@ -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 <https://github.com/Alorel>
// Seulgi Kim <https://github.com/sgkim126>
@@ -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;

View File

@@ -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();