Skip to content

WorkerPool based on worker_threads that allows executing synchronous functions asynchronously using Workers stored in pool.

License

Notifications You must be signed in to change notification settings

DarthPigrum/worker-executor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WorkerPool based on worker_threads that allows executing synchronous functions asynchronously using Workers stored in pool

Build Status Codacy Badge npm version

Usage

const WorkerPool = require('worker-executor');
const hardFunction = (n) => {
  const somelib = require('somelib'); //require should be inside the function
  //do some calculations
  return `Result of calculations #${n}`;
};
const pool = new WorkerPool(4);
const emptyPool = new WorkerPool();
emptyPool.allowSpawn = true; //set this flag if you want to allow spawning additional forks
const task1 = pool.run(hardFunction, 1);
const task2 = emptyPool.run(hardFunction, 2);
task1.promise.then(console.log);
task2.promise.then(console.log);

Warning

NodeJS with version below 11.7.0 is unsupported but it may still work with flag --experimental-worker

About

WorkerPool based on worker_threads that allows executing synchronous functions asynchronously using Workers stored in pool.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published