Gathering detailed insights and metrics for queue
Gathering detailed insights and metrics for queue
Gathering detailed insights and metrics for queue
Gathering detailed insights and metrics for queue
npm install queue
Typescript
Module System
Node Version
NPM Version
99.8
Supply Chain
99.5
Quality
76
Maintenance
100
Vulnerability
100
License
JavaScript (98.85%)
HTML (1.15%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
773 Stars
243 Commits
68 Forks
10 Watchers
2 Branches
14 Contributors
Updated on Jul 06, 2025
Latest Version
7.0.0
Package Id
queue@7.0.0
Unpacked Size
19.11 kB
Size
5.94 kB
File Count
5
NPM Version
8.11.0
Node Version
17.9.1
Published on
Apr 11, 2023
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
3
____ __ _____ __ _____
/ __ `/ / / / _ \/ / / / _ \
/ /_/ / /_/ / __/ /_/ / __/
\__, /\__,_/\___/\__,_/\___/
/_/
Asynchronous function queue with adjustable concurrency.
This module exports a class Queue
that implements most of the Array
API. Pass async functions (ones that accept a callback or return a promise) to an instance's additive array methods. Processing begins when you call q.start()
.
Do npm run example
or npm run dev
and open the example directory (and your console) to run the following program:
1import Queue from 'queue' 2 3const q = new Queue({ results: [] }) 4 5// add jobs using the familiar Array API 6q.push(cb => { 7 const result = 'two' 8 cb(null, result) 9}) 10 11q.push( 12 cb => { 13 const result = 'four' 14 cb(null, result) 15 }, 16 cb => { 17 const result = 'five' 18 cb(null, result) 19 } 20) 21 22// jobs can accept a callback or return a promise 23q.push(() => { 24 return new Promise((resolve, reject) => { 25 const result = 'one' 26 resolve(result) 27 }) 28}) 29 30q.unshift(cb => { 31 const result = 'one' 32 cb(null, result) 33}) 34 35q.splice(2, 0, cb => { 36 const result = 'three' 37 cb(null, result) 38}) 39 40// use the timeout feature to deal with jobs that 41// take too long or forget to execute a callback 42q.timeout = 100 43 44q.addEventListener('timeout', e => { 45 console.log('job timed out:', e.detail.job.toString().replace(/\n/g, '')) 46 e.detail.next() 47}) 48 49q.push(cb => { 50 setTimeout(() => { 51 console.log('slow job finished') 52 cb() 53 }, 200) 54}) 55 56q.push(cb => { 57 console.log('forgot to execute callback') 58}) 59 60// jobs can also override the queue's timeout 61// on a per-job basis 62function extraSlowJob (cb) { 63 setTimeout(() => { 64 console.log('extra slow job finished') 65 cb() 66 }, 400) 67} 68 69extraSlowJob.timeout = 500 70q.push(extraSlowJob) 71 72// jobs can also opt-out of the timeout altogether 73function superSlowJob (cb) { 74 setTimeout(() => { 75 console.log('super slow job finished') 76 cb() 77 }, 1000) 78} 79 80superSlowJob.timeout = null 81q.push(superSlowJob) 82 83// get notified when jobs complete 84q.addEventListener('success', e => { 85 console.log('job finished processing:', e.detail.toString().replace(/\n/g, '')) 86 console.log('The result is:', e.detail.result) 87}) 88 89// begin processing, get notified on end / failure 90q.start(err => { 91 if (err) throw err 92 console.log('all done:', q.results) 93})
npm install queue
yarn add queue
npm test
npm run dev // for testing in a browser, open test directory (and your console)
const q = new Queue([opts])
Constructor. opts
may contain initial values for:
q.concurrency
q.timeout
q.autostart
q.results
q.start([cb])
Explicitly starts processing jobs and provides feedback to the caller when the queue empties or an error occurs. If cb is not passed a promise will be returned.
q.stop()
Stops the queue. can be resumed with q.start()
.
q.end([err])
Stop and empty the queue immediately.
Array
Mozilla has docs on how these methods work here. Note that slice
does not copy the queue.
q.push(element1, ..., elementN)
q.unshift(element1, ..., elementN)
q.splice(index , howMany[, element1[, ...[, elementN]]])
q.pop()
q.shift()
q.slice(begin[, end])
q.reverse()
q.indexOf(searchElement[, fromIndex])
q.lastIndexOf(searchElement[, fromIndex])
q.concurrency
Max number of jobs the queue should process concurrently, defaults to Infinity
.
q.timeout
Milliseconds to wait for a job to execute its callback. This can be overridden by specifying a timeout
property on a per-job basis.
q.autostart
Ensures the queue is always running if jobs are available. Useful in situations where you are using a queue only for concurrency control.
q.results
An array to set job callback arguments on.
q.length
Jobs pending + jobs to process (readonly).
q.dispatchEvent(new QueueEvent('start', { job }))
Immediately before a job begins to execute.
q.dispatchEvent(new QueueEvent('success', { result: [...result], job }))
After a job executes its callback.
q.dispatchEvent(new QueueEvent('error', { err, job }))
After a job passes an error to its callback.
q.dispatchEvent(new QueueEvent('timeout', { next, job }))
After q.timeout
milliseconds have elapsed and a job has not executed its callback.
q.dispatchEvent(new QueueEvent('end', { err }))
After all jobs have been processed
The latest stable release is published to npm. Abbreviated changelog below:
start
event before job begins (@joelgriffith)timeout
property on a job to override the queue's timeout (@joelgriffith)Infinity
q.start()
to accept an optional callback executed on q.emit('end')
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 10/16 approved changesets -- score normalized to 6
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
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