ready-queue
v1.0.0
Published
Ready-queue ensures initialization method only run once, and queues listeners which are registered to it.
Downloads
420
Maintainers
Readme
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 aPromise
.- args
any
arguments which is from.add(args)
method
- args
- retry
number=0
how many timesqueue
will retry if fails.
.add(args)
returns Promise
License
MIT