Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
thread-pool-node
Advanced tools
Readme
A Thread pool for nodejs worker-threads. It relies on the generic-pool library to handle the resource management.
npm install thread-pool-node
or with yarn:
yarn add thread-pool-node
// index.js
const createPool = require('thread-pool-node')
const pool = createPool({
workerPath: './path/to/worker.js',
workerOptions: {
workerData: {
magicNumber: 42
}
},
poolOptions: { // passed to generic-pool
min: 2,
max: 4
}
})
const worker = await pool.acquire();
const onMessage = result => {
// do something with the result
console.log({ result });
// release back to thread pool
pool.release(worker);
worker.removeListener("message", onMessage);
};
worker.on("message", onMessage);
worker.postMessage(args);
// worker.js
const { parentPort, workerData } = require("worker_threads");
parentPort.on("message", message => {
parentPort.postMessage(aCPUBoundTask(workerData.magicNumber))
});
createPool
: Creates a new worker-threads pool according to the given pool optionsasync Pool#acquire
- Returns a new ready to be used worker from the pool.async Pool#release
- Releases the worker back to the pool.For info on how to configure the pool to meet your needs, and more useful pool APIs, see generic-pool
FAQs
Worker threads pool based on generic-pool
The npm package thread-pool-node receives a total of 78 weekly downloads. As such, thread-pool-node popularity was classified as not popular.
We found that thread-pool-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.