0.0.5 • Published 7 years ago
ssfq v0.0.5
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 processedlocked
queue is busy processing tasksunlocked
queue is idlepaused
queue was paused and won't process any task until resumedresumed
queue will continue processing tasks