batched

Async chaining sugar. Turn async methods into a batch

batched

Async chaining sugar. Turn async methods into a batch

var batched = require("../index")
 
var asyncThing = {
    _state: {
        1: 1
        , 2: 2
        , 3: 3
    }
    , getAllfunction (callback) {
        var state = this._state
        process.nextTick(function () {
            callback(null, state)
        })
    }
    , getfunction (idcallback) {
        var state = this._state
        process.nextTick(function () {
            callback(null, state[id])
        })
    }
    , setfunction (idvaluecallback) {
        var state = this._state
        process.nextTick(function () {
            state[id] = value
            callback(null)
        })
    }
    , delfunction (idcallback) {
        var state = this._state
        process.nextTick(function () {
            delete state[id]
            callback(null)
        })
    }
}
 
batched(asyncThing)
    .set("foo", "bar")
    .set("hello", "world")
    .del("1")
    .del("2")
    .getAll(function (errresults) {
        console.log("results!", results)
    })

npm install batched

  • Raynos