Class: PromiseQueue

PromiseQueue(options)

The PromiseQueue class, keeps track of a queue containing native Promises. It will process each Promise sequentially, or parallel depending on the concurrency.

Constructor

new PromiseQueue(options)

PromiseQueue constructor

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
concurrency number <optional>
1

Number of parallel requests allowed

throttle number <optional>
0

Wait in ms between requests

rateLimit Object <optional>
Properties
Name Type Attributes Description
max number <optional>

Maximum number of queue items per time unit

per number <optional>

Time in ms

Members

size

PromiseQueue size getter.

Methods

abort()

Abort all non-executed Promises in the queue.

add(fn, options) → {Promise}

Add a Promise to the queue, if the queue is empty it will be executed immediately, else it will wait for the other Promises to resolve/reject.

Parameters:
Name Type Description
fn function

Wrapper function which should return a Promise

options Object
Properties
Name Type Description
priority boolean

If true promise will be added as first item

Returns:
Type
Promise

remove(fn, rejectopt)

Remove a Promise from the PromiseQueue

Parameters:
Name Type Attributes Description
fn function

Wrapper function which should return a Promise

reject boolean <optional>

If undefined the Promise to be removed will be rejected