Node.js multithreading toolkit
npm install multithreading-toolkitbash
npm install multithreading-toolkit --save
`$3
$3
- source: Function or path to the module that exports the function (Function/String)
- options: Options when creating a function (Object):
- options.returnTimeout: Return timeout (milliseconds) (Default: 60000)
- options.eval: true, if the function was passed as the source, false if the path to the module was passed as the source (Default: false)
- options.execArgv: execArgv for Worker instance (Array) (Default: [])
- options.pool: Do I need to use a pool of workers (Bool) (Default: false)
- options.poolOptions: Pool options for generic-pool
$3
`js
'use strict';const myReturnTimeout = 1000000;
const { workerThreadsFunction } = require('multithreading-toolkit');
const someFunction = workerThreadsFunction(function (arg1, arg2, arg3) {
// arg1, arg2, arg3 - Some data for calculations
// Some heavy calculations, which usually block the thread
return 'Some result';
}, {
eval: true
});
// Call the function, passing in an array of arguments
someFunction([1, 2, 3], {returnTimeout: myReturnTimeout}).then(console.log).catch(console.error);
`$3
$3
- source: Function or path to the module that exports the function (Function/String)
- options: Options when creating a function (Object):
- options.returnTimeout: Return timeout (milliseconds) (Default: 60000)
- options.eval: true, if the function was passed as the source, false if the path to the module was passed as the source (Default: false)
- options.forkOptions: options for child_process.fork
- options.pool: Do I need to use a pool of workers (Bool) (Default: false)
- options.poolOptions: Pool options for generic-pool
$3
`js
'use strict';const myReturnTimeout = 1000000;
const { forkFunction } = require('multithreading-toolkit');
const someFunction = forkFunction(function (arg1, arg2, arg3) {
// arg1, arg2, arg3 - Some data for calculations
// Some heavy calculations, which usually block the thread
return 'Some result';
}, {
eval: true
});
// Call the function, passing in an array of arguments
someFunction([1, 2, 3], {returnTimeout: myReturnTimeout}).then(console.log).catch(console.error);
``