subservient
Version:
The easiest way to multithread in node.js
13 lines (10 loc) • 311 B
text/typescript
import { createFarm } from '..//..';
// Create a worker farm
const farm = createFarm('./out/examples/basic/worker.js', {
maxSize: 1, // Maximum amount of workers
});
(async () => {
const res = await (await farm.spawn()).hardTask();
console.log(`Thread returned: ${res}`);
await farm.end();
})();