![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
A promise based, dynamic priority queue runner, with concurrency limiting.
The run-queue npm package is designed to manage and execute a queue of tasks with dependencies. It allows you to define tasks and their dependencies, ensuring that tasks are executed in the correct order.
Creating a Queue
This feature allows you to create a new queue with a specified maximum concurrency. The maxConcurrency option controls how many tasks can run simultaneously.
const RunQueue = require('run-queue');
const queue = new RunQueue({ maxConcurrency: 2 });
Adding Tasks to the Queue
This feature allows you to add tasks to the queue. Each task can have dependencies, which are specified as an array of task names that must be completed before the task can run.
queue.add('task1', [], () => console.log('Task 1 executed'));
queue.add('task2', ['task1'], () => console.log('Task 2 executed after Task 1'));
queue.add('task3', ['task1'], () => console.log('Task 3 executed after Task 1'));
Running the Queue
This feature allows you to run the queue. The callback function is called when all tasks have been completed or if an error occurs.
queue.run((err) => {
if (err) console.error('Error running queue:', err);
else console.log('All tasks completed successfully');
});
The async package provides a wide range of utilities for working with asynchronous JavaScript, including functions for managing queues. It offers more features and flexibility compared to run-queue, but can be more complex to use.
The p-queue package is a promise-based queue implementation for managing asynchronous tasks. It offers similar functionality to run-queue but uses promises instead of callbacks, making it more suitable for modern JavaScript development.
The queue package is a simple and efficient queue implementation for managing tasks. It provides basic queue functionality with a focus on simplicity and performance, but lacks some of the advanced features of run-queue.
A promise based, dynamic priority queue runner, with concurrency limiting.
const RunQueue = require('run-queue')
const queue = new RunQueue({
maxConcurrency: 1
})
queue.add(1, example, [-1])
for (let ii = 0; ii < 5; ++ii) {
queue.add(0, example, [ii])
}
const finished = []
queue.run().then(
console.log(finished)
})
function example (num, next) {
setTimeout(() => {
finished.push(num)
next()
}, 5 - Math.abs(num))
}
would output
[ 0, 1, 2, 3, 4, -1 ]
If you bump concurrency to 2
, then you get:
[ 1, 0, 3, 2, 4, -1 ]
The concurrency means that they don't finish in order, because some take
longer than others. Each priority level must finish entirely before the
next priority level is run. See
PRIORITIES below. This is
even true if concurrency is set high enough that all of the regular queue
can execute at once, for instance, with maxConcurrency: 10
:
[ 4, 3, 2, 1, 0, -1 ]
Create a new queue. Options may contain:
1
) The maximum number of jobs to execute at once.Add a new job to the end of the queue at priority prio
that will run fn
with args
. If fn
is async then it should return a Promise.
Start running the job queue. Returns a Promise that resolves when either all the jobs are complete or a job ends in error (throws or returns a rejected promise). If a job ended in error then this Promise will be rejected with that error and no further queue running will be done.
Priorities are any integer value >= 0.
Lowest is executed first.
Priorities essentially represent distinct job queues. All jobs in a queue must complete before the next highest priority job queue is executed.
This means that if you have two queues, 0
and 1
then ALL jobs in 0
must complete before ANY execute in 1
. If you add new 0
level jobs
while 1
level jobs are running then it will switch back processing the 0
queue and won't execute any more 1
jobs till all of the new 0
jobs
complete.
FAQs
A promise based, dynamic priority queue runner, with concurrency limiting.
The npm package run-queue receives a total of 4,196,858 weekly downloads. As such, run-queue popularity was classified as popular.
We found that run-queue demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.