Home

Awesome

qool

a leveldb backed Queue

npm status

Example

Simple

const Qool = require('qool')
const level = require('level-bytewise')

const db = level('db')
const queue = Qool.create(db)

queue.enqueue('a')
queue.enqueue('b', (err) => {})

queue.dequeue()
queue.dequeue((err, value) => {})
notes

Enqueue and Dequeue are batched under the hood, so callbacks are invoked synchronously. This means that you can only include a last callback and forgo all the others for Enqueues and Dequeues that happen in the same tick

Lease

const Qool = require('qool')
const level = require('level-bytewise')

const db = level('db')
const queue = Qool.create(db, 1000 * 10)

queue.enqueue('a')
queue.enqueue('b', (err) => {})

queue.lease((err, leaseKey, value) => {
    // do something with the data

    // delete the item permanently from the queue
    queue.delete(leaseKey, (err) => {

    })
})

// TBD
// lease with a non default timeout
//queue.leaseWithTimeout(1000 * 2, (err, leaseKey, value) => {})

Peek

const Qool = require('qool')
const level = require('level-bytewise')

const db = level('db')
const queue = Qool.create(db)

queue.enqueue('a')
queue.enqueue('b', (err) => {})

queue.peek((err, value) => {
    // value === 'a'
})

queue.peekMany((err, results) => {
    // results === [{ key: ..., value: 'a' }, { key: ..., value: 'b' }]
})

Some ramblings on internal design are here

license

TODO

MIT © yaniv kessler