ready-queue

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i ready-queue

Weekly Downloads

118

Version

1.0.0

License

MIT

Last publish

Collaborators

  • kael