Package Exports
- microjob
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (microjob) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Microjob
A tiny wrapper for turning Node.js threads in easy-to-use routines for CPU-bound.
Introduction
Microjob is a tiny wrapper for Node.js threads and is intended to perform heavy CPU loads using anonymous functions.
So, Microjob treats Node.js threads as temporary working units: if you need to spawn a long-living thread, then you should use the default API.
From version v0.1.0 microjob uses a Worker Pool ð
Microjob follows the same line of the original Node.js documentation: use it only for CPU-bound jobs and not for I/O-bound purposes. Quoting the documentation:
Workers are useful for performing CPU-intensive JavaScript operations; do not use them for I/O, since Node.jsâs built-in mechanisms for performing operations asynchronously already treat it more efficiently than Worker threads can.
Microjob can be used only with Node.js 10.5+ and with the --experimental-worker flag activated, otherwise it won't work.
More details explained in: Microjob: a tiny multithreading library for Node.js
Installation
Via npm:
$ npm install --save microjobQuick Example
(async () => {
const { job, start, stop } = require("microjob");
try {
// start the worker pool
await start();
// this function will be executed in another thread
const res = await job(() => {
let i = 0;
for (i = 0; i < 1000000; i++) {
// heavy CPU load ...
}
return i;
});
console.log(res); // 1000000
} catch (err) {
console.error(err);
} finally {
// shutdown worker pool
await stop();
}
})();Features
- ð¢ïž Worker Pool
- ð¥ auto self-healing
- ð easy and simple
- ð supports both sync and async jobs
- ð¡ïž huge test coverage
- ð well documented
Documentation
Dive deep into the documentation to find more examples: Guide