This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
2020-11-01 22:46:04 +00:00

22 lines
472 B
JavaScript

var workerpool = require('..');
// create a worker pool
var pool = workerpool.pool();
// create a static function
function add(a, b) {
return a + b;
}
// offload execution of a function to the worker pool
pool.exec(add, [3, 4])
.then(function (result) {
console.log('result', result); // outputs 7
})
.catch(function (err) {
console.error(err);
})
.then(function () {
pool.terminate(); // terminate all workers when done
});