fastq
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
reusify | 1.0.4 | 4.02 kB | MIT | prod |
FastQ is a popular npm package that offers a high performance, in-memory work queue. Its main purpose is to manage tasks efficiently in a fast queueing system, which is especially beneficial for Node.js applications where managing asynchronous operations is critical. Elegant in its simplicity, FastQ outperforms several other task queue packages according to benchmarks provided on its official repository.
To use FastQ, start by installing the package using npm with the command npm i fastq --save
. After installation, you can import it into your application and create a queue. You should define a worker function and the level of concurrency for the tasks. FastQ provides both a callback API and a promise API. The tasks will be processed by the worker function in accordance with the queue.
A basic usage example is as follows:
'use strict'
const queue = require('fastq')(worker, 1)
queue.push(42, function (err, result) {
if (err) { throw err }
console.log('the result is', result)
})
function worker (arg, cb) {
cb(null, arg * 2)
}
In this example, a worker function is defined which doubles the argument passed to it. The push
method is used to add a task (in this case, the number 42) to the queue. The second argument to the push
method is a callback function which is executed once the task is processed.
FastQ can also be used with TypeScript and offers methods to pause, resume, check if the queue is idle, get the length of the queue, and much more.
The complete FastQ documentation can be found in its official GitHub repository at https://github.com/mcollina/fastq. This documentation provides a comprehensive guide for installation, usage, API details, and several usage examples for various scenarios. FastQ's APIs, such as push
, unshift
, pause
, resume
and many more, are particularly detailed in the documentation.