
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
worker-pool-task-queue
Advanced tools
The library is specifically designed for Node.js environments and is based upon the native worker_threads module
This library provides a solution for managing concurrent tasks in a Node.js environment. It leverages a combination of worker threads organized into a pool and a task queue system to efficiently execute tasks, ensuring optimal utilization of system resources and enhancing application performance.
The library is specifically designed for Node.js environments and is based upon the native worker_threads module (https://nodejs.org/api/worker_threads.html).
The library creates a pool of worker threads with a specified size. Workers are managed efficiently, ensuring they are available for processing tasks when needed.
Implements a task queue mechanism to handle tasks that cannot be immediately processed due to the unavailability of worker threads. Queued tasks are executed in a sequential manner, preventing overload and ensuring reliable task execution.
Dynamically scales the worker pool size based on demand, ensuring optimal resource utilization. New workers are added to the pool as needed, allowing the system to handle increased workloads effectively.
First, install the worker-pool-task-queue module using npm:
$ npm install worker-pool-task-queue
Import the WorkerPool class from the installed module and set up a worker pool with a specific pool size, worker script file path, and maximum number of workers:
const WorkerPool = require('worker-pool-task-queue');
const path = require('path');
// Create a worker pool with 5 workers, using 'Worker.js' as the worker script
const pool = new WorkerPool(poolSize = 5, path.join(__dirname, 'Worker.js'), maxWorkers = 15);
const { parentPort } = require('worker_threads');
parentPort.on('message', async (message) => {
const { fn } = message;
// execute 'myfunc' here, return result in postMessage
setTimeout(() => {
parentPort.postMessage({ executed: `function ${fn} true` });
}, 1000);
});
Create functions to execute tasks using the worker pool. For example, you can define an executeTask function that runs a specific function called 'myfunc' in the worker pool:
async function executeTask() {
try {
const result = await pool.runTask({ fn: 'myfunc', params: { set: true } });
console.log(result);
} catch (error) {
console.error(error);
}
}
You can then call this function multiple times using a loop or any other logic as needed:
async function executeTasksMultipleTimes() {
for (let i = 0; i < 4; i++) {
await executeTask();
}
}
executeTasksMultipleTimes();
This library used jsdoc types and is tested in Chrome
FAQs
The library is specifically designed for Node.js environments and is based upon the native worker_threads module
The npm package worker-pool-task-queue receives a total of 2 weekly downloads. As such, worker-pool-task-queue popularity was classified as not popular.
We found that worker-pool-task-queue demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.