npm.io
1.0.0 • Published 9 years ago

ready-queue

Licence
MIT
Version
1.0.0
Deps
0
Vulns
0
Weekly
0

Build Status

ready-queue

Ready-queue ensures initialization method only run once, and queues listeners which are registered to it.

Install

$ npm install ready-queue --save

Usage

const queue = require('ready-queue')

const q = queue({
  load: (userId) => {
    return getUserPromise(userId)
  }
})

q.add(123).then((userObject) => {
  userObject
})

q.add(123).then((userObject) => {
  // `getUserPromise(123)` only runs once
})

q.add(234).then((userObject) => {
  // then `getUserPromise(234)` runs
})
queue({load, retry = 0})
  • load function(args) if the function is asynchronous, it should return a Promise.
    • args any arguments which is from .add(args) method
  • retry number=0 how many times queue will retry if fails.
.add(args)

returns Promise

License

MIT

Keywords