Irina Glushko 2389e7160b HW1 done | 3 năm trước cách đây | |
---|---|---|
.. | ||
.github | 3 năm trước cách đây | |
test | 3 năm trước cách đây | |
LICENSE | 3 năm trước cách đây | |
README.md | 3 năm trước cách đây | |
bench.js | 3 năm trước cách đây | |
example.js | 3 năm trước cách đây | |
index.d.ts | 3 năm trước cách đây | |
package.json | 3 năm trước cách đây | |
queue.js | 3 năm trước cách đây |
Fast, in memory work queue.
Benchmarks (1 million tasks):
Obtained on node 12.16.1, on a dedicated server.
If you need zero-overhead series function call, check out fastseries. For zero-overhead parallel function call, check out fastparallel.
npm i fastq --save
'use strict'
var 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, 42 * 2)
}
or
var queue = require('fastq').promise(worker, 1)
async function worker (arg) {
return 42 * 2
}
async function run () {
const result = await queue.push(42)
console.log('the result is', result)
})
}
run()
'use strict'
var that = { hello: 'world' }
var queue = require('fastq')(that, worker, 1)
queue.push(42, function (err, result) {
if (err) { throw err }
console.log(this)
console.log('the result is', result)
})
function worker (arg, cb) {
console.log(this)
cb(null, 42 * 2)
}
fastqueue()
queue#push()
queue#unshift()
queue#pause()
queue#resume()
queue#idle()
queue#length()
queue#getQueue()
queue#kill()
queue#killAndDrain()
queue#error()
queue#concurrency
queue#drain
queue#empty
queue#saturated
fastqueue.promise()
Creates a new queue.
Arguments:
that
, optional context of the worker
function.worker
, worker function, it would be called with that
as this
,
if that is specified.concurrency
, number of concurrent tasks that could be executed in
parallel.Add a task at the end of the queue. done(err, result)
will be called
when the task was processed.
Add a task at the beginning of the queue. done(err, result)
will be called
when the task was processed.
Pause the processing of tasks. Currently worked tasks are not stopped.
Resume the processing of tasks.
Returns false
if there are tasks being processed or waiting to be processed.
true
otherwise.
Returns the number of tasks waiting to be processed (in the queue).
Returns all the tasks be processed (in the queue). Returns empty array when there are no tasks
Removes all tasks waiting to be processed, and reset drain
to an empty
function.
Same than kill
but the drain
function will be called before reset to empty.
Set a global error handler. handler(err, task)
will be called
when any of the tasks return an error.
Property that returns the number of concurrent tasks that could be executed in parallel. It can be altered at runtime.
Function that will be called when the last item from the queue has been processed by a worker. It can be altered at runtime.
Function that will be called when the last item from the queue has been assigned to a worker. It can be altered at runtime.
Function that will be called when the queue hits the concurrency limit. It can be altered at runtime.
Creates a new queue with Promise
apis. It also offers all the methods
and properties of the object returned by fastqueue
with the modified
push
and unshift
methods.
Node v10+ is required to use the promisified version.
Arguments:
that
, optional context of the worker
function.worker
, worker function, it would be called with that
as this
,
if that is specified. It MUST return a Promise
.concurrency
, number of concurrent tasks that could be executed in
parallel.Add a task at the end of the queue. The returned Promise
will be fulfilled
when the task is processed.
Add a task at the beginning of the queue. The returned Promise
will be fulfilled
when the task is processed.
ISC