queue-that-promise
Push promises to a queue. The queue runs. That's all.
Last updated 4 years ago by andytjoslin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install queue-that-promise 
SYNC missed versions from official npm registry.

queue-that-promise Build Status

Push promises to a queue. The queue runs in order. That's all. 500b gzipped.

Install

$ npm install --save queue-that-promise

Usage

var Queue = require('queue-that-promise')
var queue = Queue()

queue.add(() => new Promise((resolve) => setTimeout(resolve, 100))
  .then(() => console.log('first'))

queue.add(() => new Promise((resolve) => setTimeout(resolve, 100))
  .then(() => console.log('second'))

queue.add(() => new Promise((resolve) => setTimeout(resolve, 100))
  .then(() => console.log('third'))

queue.done().then(() => console.log('done'))

// Wait 100ms...
// => "first"
// Wait 100ms...
// => "second"
// Wait 100ms...
// => "third"
// => "done"

API

Queue() -> queue

Returns a queue instance.

queue.done() -> Promise

Returns a promise that will be resolved once the queue is empty.

queue.add(callback<Promise> | Array<callback<Promise>>) -> Promise

Adds a callback or multiple callbacks to the queue.

The callback will run after all previously added callbacks have finished.

Returns a promise that will be resolved or rejected once the given callback's returned promise is resolved or rejected.

queue.count() -> number

Returns the current length of the queue.

Related

License

MIT © Andrew Joslin

Current Tags

  • 1.2.3                                ...           latest (4 years ago)

6 Versions

  • 1.2.3                                ...           4 years ago
  • 1.2.2                                ...           4 years ago
  • 1.2.1                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (4)

Copyright 2014 - 2016 © taobao.org |