Gathering detailed insights and metrics for @hysc/p-queue
Gathering detailed insights and metrics for @hysc/p-queue
Gathering detailed insights and metrics for @hysc/p-queue
Gathering detailed insights and metrics for @hysc/p-queue
npm install @hysc/p-queue
Typescript
Module System
Min. Node Version
Node Version
NPM Version
71.7
Supply Chain
98.9
Quality
78.8
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3,768 Stars
146 Commits
193 Forks
21 Watchers
2 Branches
33 Contributors
Updated on Jul 15, 2025
Latest Version
6.3.0
Package Id
@hysc/p-queue@6.3.0
Unpacked Size
31.77 kB
Size
7.90 kB
File Count
13
NPM Version
8.5.0
Node Version
16.14.2
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
Promise queue with concurrency control
Useful for rate-limiting async (or sync) operations. For example, when interacting with a REST API or when doing CPU/memory intensive tasks.
$ npm install p-queue
Here we run only one promise at the time. For example, set concurrency
to 4 to run four promises at the same time.
1const {default: PQueue} = require('p-queue'); 2const got = require('got'); 3 4const queue = new PQueue({concurrency: 1}); 5 6(async () => { 7 await queue.add(() => got('sindresorhus.com')); 8 console.log('Done: sindresorhus.com'); 9})(); 10 11(async () => { 12 await queue.add(() => got('ava.li')); 13 console.log('Done: ava.li'); 14})(); 15 16(async () => { 17 const task = await getUnicornTask(); 18 await queue.add(task); 19 console.log('Done: Unicorn task'); 20})();
Returns a new queue
instance, which is an EventEmitter3
subclass.
Type: object
Type: number
Default: Infinity
Minimum: 1
Concurrency limit.
Type: number
Per-operation timeout in milliseconds. Operations fulfill once timeout
elapses if they haven't already.
Type: boolean
Default: false
Whether or not a timeout is considered an exception.
Type: boolean
Default: true
Whether queue tasks within concurrency limit, are auto-executed as soon as they're added.
Type: Function
Class with a enqueue
and dequeue
method, and a size
getter. See the Custom QueueClass section.
Type: number
Default: Infinity
Minimum: 1
The max number of runs in the given interval of time.
Type: number
Default: 0
Minimum: 0
The length of time in milliseconds before the interval count resets. Must be finite.
Type: boolean
Default: false
Whether the task must finish in the given interval or will be carried over into the next interval count.
PQueue
instance.
Adds a sync or async task to the queue. Always returns a promise.
Type: Function
Promise-returning/async function.
Type: object
Type: number
Default: 0
Priority of operation. Operations with greater priority will be scheduled first.
Same as .add()
, but accepts an array of sync or async functions and returns a promise that resolves when all functions are resolved.
Put queue execution on hold.
Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via options.autoStart = false
or by .pause()
method.)
Returns this
(the instance).
Returns a promise that settles when the queue becomes empty.
Can be called multiple times. Useful if you for example add additional items at a later time.
Returns a promise that settles when the queue becomes empty, and all promises have completed; queue.size === 0 && queue.pending === 0
.
The difference with .onEmpty
is that .onIdle
guarantees that all work from the queue has finished. .onEmpty
merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
Clear the queue.
Size of the queue.
Size of the queue, filtered by the given options.
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
1const queue = new PQueue(); 2 3queue.add(async () => '🦄', {priority: 1}); 4queue.add(async () => '🦄', {priority: 0}); 5queue.add(async () => '🦄', {priority: 1}); 6 7console.log(queue.sizeBy({priority: 1})); 8//=> 2 9 10console.log(queue.sizeBy({priority: 0})); 11//=> 1
Number of pending promises.
Whether the queue is currently paused.
Emitted as each item is processed in the queue for the purpose of tracking progress.
1const delay = require('delay'); 2const {default: PQueue} = require('p-queue'); 3 4const queue = new PQueue({concurrency: 2}); 5 6let count = 0; 7queue.on('active', () => { 8 console.log(`Working on item #${++count}. Size: ${queue.size} Pending: ${queue.pending}`); 9}); 10 11queue.add(() => Promise.resolve()); 12queue.add(() => delay(2000)); 13queue.add(() => Promise.resolve()); 14queue.add(() => Promise.resolve()); 15queue.add(() => delay(500));
A more advanced example to help you understand the flow.
1const delay = require('delay'); 2const {default: PQueue} = require('p-queue'); 3 4const queue = new PQueue({concurrency: 1}); 5 6(async () => { 7 await delay(200); 8 9 console.log(`8. Pending promises: ${queue.pending}`); 10 //=> '8. Pending promises: 0' 11 12 (async () => { 13 await queue.add(async () => '🐙'); 14 console.log('11. Resolved') 15 })(); 16 17 console.log('9. Added 🐙'); 18 19 console.log(`10. Pending promises: ${queue.pending}`); 20 //=> '10. Pending promises: 1' 21 22 await queue.onIdle(); 23 console.log('12. All work is done'); 24})(); 25 26(async () => { 27 await queue.add(async () => '🦄'); 28 console.log('5. Resolved') 29})(); 30console.log('1. Added 🦄'); 31 32(async () => { 33 await queue.add(async () => '🐴'); 34 console.log('6. Resolved') 35})(); 36console.log('2. Added 🐴'); 37 38(async () => { 39 await queue.onEmpty(); 40 console.log('7. Queue is empty'); 41})(); 42 43console.log(`3. Queue size: ${queue.size}`); 44//=> '3. Queue size: 1` 45 46console.log(`4. Pending promises: ${queue.pending}`); 47//=> '4. Pending promises: 1'
$ node example.js
1. Added 🦄
2. Added 🐴
3. Queue size: 1
4. Pending promises: 1
5. Resolved 🦄
6. Resolved 🐴
7. Queue is empty
8. Pending promises: 0
9. Added 🐙
10. Pending promises: 1
11. Resolved 🐙
12. All work is done
For implementing more complex scheduling policies, you can provide a QueueClass in the options:
1class QueueClass { 2 constructor() { 3 this._queue = []; 4 } 5 6 enqueue(run, options) { 7 this._queue.push(run); 8 } 9 10 dequeue() { 11 return this._queue.shift(); 12 } 13 14 get size() { 15 return this._queue.length; 16 } 17 18 filter(options) { 19 return this._queue; 20 } 21}
p-queue
will call corresponding methods to put and get operations from this queue.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
1 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 3/30 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
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