This is simple small library for multithreading.
If you need handle CPU-intensive task, without blocking main thread.
First you need to create an instance of worker pool.
const N = 7; // count of threads you want. Usually equals count of your cores minus 1
const workerPool = new WorkerPool(N);
Next you just send command to your worker pool to execute some commands. For instance, your task is to find sum of array.
workerPool
.executeTask((A) => A.reduce((prev, acc) => prev + acc, 0), getArray(250000))
.then((result) => console.log(result))
.catch((err) => console.error(err))
Method getArray(N) returns list with size N, where N is integer.
Method executeTask() returns promise, so handling result of the task is quite easy.
With async/await syntax getting result looks like this.
const result = await workerPool.executeTask((A) => A.reduce((prev, acc) => prev + acc, 0), getArray(250000))