Gathering detailed insights and metrics for queue-promise
Gathering detailed insights and metrics for queue-promise
Gathering detailed insights and metrics for queue-promise
Gathering detailed insights and metrics for queue-promise
A simple, dependency-free library for concurrent promise-based queues. Comes with with concurrency and timeout control.
npm install queue-promise
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (93.95%)
TypeScript (6.05%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
92 Stars
869 Commits
11 Forks
3 Watchers
13 Branches
4 Contributors
Updated on Feb 07, 2025
Latest Version
2.2.1
Package Id
queue-promise@2.2.1
Unpacked Size
28.56 kB
Size
8.80 kB
File Count
7
NPM Version
7.10.0
Node Version
14.16.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
37
queue-promise
is a small, dependency-free library for promise-based queues. It will execute enqueued tasks concurrently at a given speed. When a task is being resolved or rejected, an event is emitted.
1$ npm install queue-promise
1import Queue from "queue-promise"; 2 3const queue = new Queue({ 4 concurrent: 1, 5 interval: 2000 6}); 7 8queue.on("start", () => /* … */); 9queue.on("stop", () => /* … */); 10queue.on("end", () => /* … */); 11 12queue.on("resolve", data => console.log(data)); 13queue.on("reject", error => console.error(error)); 14 15queue.enqueue(asyncTaskA); // resolved/rejected after 0ms 16queue.enqueue(asyncTaskB); // resolved/rejected after 2000ms 17queue.enqueue(asyncTaskC); // resolved/rejected after 4000ms
1import Queue from "queue-promise"; 2 3const queue = new Queue({ 4 concurrent: 1, 5 interval: 2000, 6 start: false, 7}); 8 9queue.enqueue(asyncTaskA); 10queue.enqueue(asyncTaskB); 11queue.enqueue(asyncTaskC); 12 13while (queue.shouldRun) { 14 // 1st iteration after 2000ms 15 // 2nd iteration after 4000ms 16 // 3rd iteration after 6000ms 17 const data = await queue.dequeue(); 18}
new Queue(options)
Create a new Queue
instance.
Option | Default | Description |
---|---|---|
concurrent | 5 | How many tasks should be executed in parallel |
interval | 500 | How often should new tasks be executed (in ms) |
start | true | Whether it should automatically execute new tasks as soon as they are added |
.enqueue(tasks)
/.add(tasks)
Adds a new task to the queue. A task should be an async function (ES2017) or return a Promise. Throws an error if the provided task
is not a valid function.
Example:
1async function getRepos(user) { 2 return await github.getRepos(user); 3} 4 5queue.enqueue(() => { 6 return getRepos("userA"); 7}); 8 9queue.enqueue(async () => { 10 await getRepos("userB"); 11}); 12 13// …equivalent to: 14queue.enqueue([() => getRepos("userA"), () => getRepos("userB")]);
.dequeue()
Executes n concurrent (based od options.concurrent
) promises from the queue. Uses global Promises. Is called automatically if options.start
is set to true
. Emits resolve
and reject
events.
Example:
1queue.enqueue(() => getRepos("userA")); 2queue.enqueue(() => getRepos("userB")); 3 4// If "concurrent" is set to 1, only one promise is executed on dequeue: 5const userA = await queue.dequeue(); 6const userB = await queue.dequeue(); 7 8// If "concurrent" is set to 2, two promises are executed concurrently: 9const [userA, userB] = await queue.dequeue();
Note:
.dequeue()
function throttles (is executed at most once per every options.interval
milliseconds).
.on(event, callback)
Sets a callback
for an event
. You can set callback for those events: start
, stop
, resolve
, reject
, dequeue
, end
.
Example:
1queue.on("dequeue", () => …); 2queue.on("resolve", data => …); 3queue.on("reject", error => …); 4queue.on("start", () => …); 5queue.on("stop", () => …); 6queue.on("end", () => …);
Note:
dequeue
, resolve
and reject
events are emitted per task. This means that even if concurrent
is set to 2
, 2
events will be emitted.
.start()
Starts the queue – it will automatically dequeue tasks periodically. Emits start
event.
1queue.enqueue(() => getRepos("userA")); 2queue.enqueue(() => getRepos("userB")); 3queue.enqueue(() => getRepos("userC")); 4queue.enqueue(() => getRepos("userD")); 5queue.start(); 6 7// No need to call `dequeue` – you can just listen for events: 8queue.on("resolve", data => …); 9queue.on("reject", error => …);
.stop()
Forces the queue to stop. New tasks will not be executed automatically even if options.start
was set to true
. Emits stop
event.
.clear()
Removes all tasks from the queue.
.started
Whether the queue is running.
.stopped
Whether the queue has been forced to stop by calling Queue.stop
.
.size
Size of the queue.
.isEmpty
Whether the queue is empty, i.e. there's no tasks.
.shouldRun
Checks whether the queue is not empty and not stopped.
1$ npm test
We have prepared multiple commands to help you develop queue-promise
on your own. You will need a local copy of Node.js installed on your machine. Then, install project dependencies using the following command:
1$ npm install
1$ npm run <command>
Command | Description |
---|---|
test | Run all test:* commands described below. |
test:flow | Test Flow types. |
test:typescript | Test TypeScript types. |
test:unit | Run unit tests. |
test:lint | Run linter tests. |
defs:flow | Build Flow type definitions. |
defs:typescript | Build TypeScript type definitions. |
clean | Clean dist directory. |
build | Build package and generate type definitions. |
watch | Build package in watch mode. |
release | Bump package version and generate a CHANGELOG.md file. |
queue-promise
was created and developed by Bartosz Łaniewski. The full list of contributors can be found here. The package is MIT licensed.
We want contributing to queue-promise
to be fun, enjoyable, and educational for anyone, and everyone. Changes and improvements are more than welcome! Feel free to fork and open a pull request. We use Conventional Commits specification for commit messages. If you have found any issues, please report them here - they are being tracked on GitHub Issues.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
46 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More