Async-Limiter
A module for limiting concurrent asynchronous actions in flight. Forked from queue.
This module exports a class Limiter
that implements some of the Array
API. Pass async functions (ones that accept a callback or return a promise) to an instance's additive array methods.
Motivation
Certain functions, like zlib
, have undesirable behavior when run at infinite concurrency.
In this case, it is actually faster, and takes far less memory, to limit concurrency.
This module should do the absolute minimum work necessary to queue up functions. PRs are welcome that would make this module faster or lighter, but new functionality is not desired.
Style should confirm to nodejs/node style.
Example
Zlib Example
Install
npm install async-limiter
Test
npm test
API
var t = new Limiter([opts])
var t = new Limiter([opts])
Constructor. opts
may contain inital values for:
t.concurrency
Instance methods
t.onDone(fn)
t.onDone(fn)
fn
will be called once and only once, when the queue is empty.
Instance methods mixed in from Array
Array
Mozilla has docs on how these methods work here.
t.push(element1, ..., elementN)
t.push(element1, ..., elementN)
t.unshift(element1, ..., elementN)
t.unshift(element1, ..., elementN)
t.splice(index , howMany[, element1[, ...[, elementN]]])
t.splice(index , howMany[, element1[, ...[, elementN]]])
Properties
t.concurrency
t.concurrency
Max number of jobs the queue should process concurrently, defaults to Infinity
.
t.length
t.length
Jobs pending + jobs to process (readonly).
Last updated