queue
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
'Queue' is a JavaScript module that provides an asynchronous function queue with adjustable concurrency. This npm package manages the execution of asynchronous tasks, making it easy to control the number of concurrent operations running at any given time. The 'Queue' class maintains the sequence of jobs and offers a similar API as JavaScript Array. It begins processing tasks or jobs when you call 'q.start()'.
This is a basic rundown on how to use 'Queue':
Installation: You can install 'Queue' with npm or yarn. Here's the command for npm:
npm install queue
And for yarn:
yarn add queue
Usage: Following is a simple workflow using 'Queue':
import Queue from 'queue'
const q = new Queue()
// add jobs using Array-like API
q.push(cb => {
// ... your async tasks
cb(null, 'result')
})
// start processing jobs
q.start(err => {
if (err) throw err
console.log('all done')
})
You can adjust concurrency by passing it in options:
const q = new Queue({ concurrency: 2 })
You can also work with promises:
q.push(() => {
return new Promise((resolve, reject) => {
// ... your async operation
resolve('result')
})
})
The complete 'Queue' API documentation is available at Mozilla Developer Network Array API as it implements most of the Array API. For more specific information about 'Queue', you can refer to the README in the package's Github repository: Queue on Github. The README includes detailed information about the constructor options, instance properties, instance methods, and available events that this package provides.