simple-async-q

0.0.1 • Public • Published

simple-queue

A simple promise and event based async queue.

Usage

const Q = require('simple-async-q')

function fn () {
  return new Promise(async (resolve, reject) => {
   // some async stuff
  })
}

const q = new Q(fn)

q.add('test')
q.add('Test')

q.start()

Constructor

The provided function has to return a Promise.

Functions

start

Start the queue.

pause

Pause the queue. The queue will be paused after the currently running task has finished.

resume

Resume the queue.

kill

Kill the queue(remove all added tasks). The queue will be killed after the currently running task has finished.

Events

finished

Is triggered when a task is finished. If no error occured then err is null. Value has 2 attributes: value which holds the resolved value from the function and payload which is the value added on q.add.

q.on('finished', (err, value) => {
})

all-finished

Is triggered when all tasks have been finished.

q.on('all-finished', () => {
})

error

Is triggered when an general error occurs. This event is not triggered when an error occurs inside the task function.

q.on('error', err => {
})

License

MIT © sys0

Readme

Keywords

none

Package Sidebar

Install

npm i simple-async-q

Weekly Downloads

2

Version

0.0.1

License

MIT

Last publish

Collaborators

  • sys0