Ready-queue ensures initialization method only run once, and queues listeners which are registered to it.
$ npm install ready-queue --save
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
})
- load
function(args)
if the function is asynchronous, it should return aPromise
.- args
any
arguments which is from.add(args)
method
- args
- retry
number=0
how many timesqueue
will retry if fails.
returns Promise
MIT