Installation
$ npm install queue-promise
Usage
import Queue from "queue-promise";
const q = new Queue( {
concurrency : 1,
interval : 2000
} );
q.on( "resolve", ...data => console.log( data ) );
q.on( "reject", error => console.error( error ) );
q.add( asyncTaskA );
q.add( asyncTaskB );
q.add( asyncTaskC );
q.add( asyncTaskD );
q.start();
API
new Queue( options )
Create a new Queue
instance with optionally injected options.
Option | Default | Description |
---|
concurrency | 5 | How many promises can be handled at the same time |
interval | 500 | How often should new promises be handled (in ms) |
public .add( promise )
Adds a promise to the queue.
public .start()
Starts the queue.
public .stop()
Stops the queue.
private .next()
Goes to the next request and stops the loop if there is no requests left.
public .on( event, callback )
Sets a callback
for an event
. You can set callback for those events:
start
stop
tick
resolve[ ...output ]
reject[ message ]
end
Tests
$ npm test