0.1.1 • Published 11 years ago

batched v0.1.1

Weekly downloads
3
License
-
Repository
github
Last release
11 years ago

batched

Async chaining sugar. Turn async methods into a batch

Example

var batched = require("../index")

var asyncThing = {
    _state: {
        1: 1
        , 2: 2
        , 3: 3
    }
    , getAll: function (callback) {
        var state = this._state
        process.nextTick(function () {
            callback(null, state)
        })
    }
    , get: function (id, callback) {
        var state = this._state
        process.nextTick(function () {
            callback(null, state[id])
        })
    }
    , set: function (id, value, callback) {
        var state = this._state
        process.nextTick(function () {
            state[id] = value
            callback(null)
        })
    }
    , del: function (id, callback) {
        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 (err, results) {
        console.log("results!", results)
    })

Installation

npm install batched

Contributors

  • Raynos

MIT Licenced

0.1.1

11 years ago

0.1.0

11 years ago