Queue
Getting Started
const Queue = require('ssfq')
const myQueue = new Queue(workerCount)
myQueue.push((next) => {
/* do something */
next()
})
class YourClass extends Queue {
find(query) {
this.push((next) => {
this._somedb.find(query, (docs) => {
this.result = docs
})
})
return this
}
each(fn) {
this.push((next) => {
this.result.forEach(fn)
})
return this
}
}
var db = YourClass()
db.find({
foo: 'bar'
})
.each((doc) => {
console.log(doc)
})
Methods
push(task, [options])
push task to queue
queue.push((next) => {
/* do something */
next()
}, {
priority: 2
})
options
- priority number, highest priority get executed first. default:
0
resume()
unpause queue and continue processing tasks
queue.resume()
pause()
pause queue (after processing current task)
queue.pause()
Events
-
task
a new task is beeing processed -
locked
queue is busy processing tasks -
unlocked
queue is idle -
paused
queue was paused and won't process any task until resumed -
resumed
queue will continue processing tasks