# batched

> Async chaining sugar. Turn async methods into a batch

Latest version **0.1.1** (published 2012-12-04) · 0 weekly downloads

## Install

```sh
npm install batched
pnpm add batched
yarn add batched
bun add batched
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2012-12-04 |
| First published | 2012-12-04 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Raynos |
| Maintainers | raynos |

## Links

- npm: https://www.npmjs.com/package/batched
- Repository: https://github.com/Raynos/batched
- Issues: https://github.com/Raynos/batched/issues
- npm.io page: https://npm.io/package/batched

## Dependencies (1)

- [to-array](https://npm.io/package/to-array.md) ~0.1.3

## Recent versions

- 0.1.1 (latest) — 2012-12-04
- 0.1.0 — 2012-12-04

## README

# batched

Async chaining sugar. Turn async methods into a batch

## Example

Basically take a hash of asynchronous functions (or methods) and
    allow you to do serialized batch of commands on it.

A batch "starts" on the nextTick and does each chained command
    in serial.

If any have a callback that callback will be
    called. Else a default callback is used that emits an
    `"error"` event on the batch if there is an error.

```js
var batched = require("batched")

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")
    .get("3", function (err, result) {
        console.log("result", result)
    })
    .getAll(function (err, results) {
        console.log("results!", results)
    })
    .on("error", function () {
        // No errors!
    })
    .once("finish", function () {
        console.log("finished")
    })

console.log("go chain go!")

```

## Installation

`npm install batched`

## Contributors

 - Raynos

## MIT Licenced

---
_Source: https://npm.io/package/batched · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
