# asyncbuilder

> simple semi-asynchronous array builder

Latest version **2.0.0** (published 2026-01-25) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

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

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-01-25 |
| First published | 2015-04-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jürgen Leschner |
| Maintainers | jldec |

## Links

- npm: https://www.npmjs.com/package/asyncbuilder
- Repository: https://github.com/jldec/pub-server-monorepo
- Homepage: https://github.com/jldec/pub-server-monorepo#readme
- Issues: https://github.com/jldec/pub-server-monorepo/issues
- npm.io page: https://npm.io/package/asyncbuilder

## Recent versions

- 2.0.0 (latest) — 2026-01-25
- 1.1.1 — 2024-09-01
- 1.1.0 — 2024-09-01
- 1.0.10 — 2022-01-09
- 1.0.9 — 2020-07-26
- 1.0.8 — 2020-04-25
- 1.0.7 — 2020-02-09
- 1.0.6 — 2019-07-13
- 1.0.5 — 2019-03-30
- 1.0.4 — 2019-02-02
- 1.0.3 — 2019-01-01
- 1.0.2 — 2018-05-04
- 1.0.1 — 2015-11-05
- 1.0.0 — 2015-04-28
- 0.6.0 — 2015-04-05
- … 1 more at https://npm.io/package/asyncbuilder/versions

## README

[![CI](https://github.com/jldec/asyncbuilder/workflows/CI/badge.svg)](https://github.com/jldec/asyncbuilder/actions)

# asyncbuilder
- builds an array containing a mix of immediate and async results
- follows node convention of using callbacks with signature `cb(err, results)`
- useful for building a sequential list in the order that async operations
  are invoked

### install

```sh
    npm install asyncbuilder
```

### usage

```js
// new is optional
var ab = new asyncbuilder(mainCallBack);

// call any number of times... for sync
ab.append(something);

// or for async
var cb = ab.asyncAppend();  // returns callback
someAsyncOperation(cb);

// call this at least once
ab.complete();
```

- no `mainCallBack()` will happen until you issue a `complete()`

- `mainCallBack(null, results)` is invoked once after the last `cb()` with no errors.

- `mainCallBack(err)` is invoked once after the first `cb(err)`.

- the original order of `append()` and `asyncAppend()` operations is respected in the results,
even if asyncAppend results arrive out of order.

- if there are only append operations, or no appends at all, `complete()`
will trigger `mainCallBack()` on nextTick.

- calling `append()` or `asyncAppend()` after `complete()` will result in an error.

### note

-  it doesn't make sense to call `asyncAppend()` from within an async operation.
   Ordering will be wrong, and `complete()` will probably have been called already.
   Instead, call `asyncAppend()` *before* the async operation
   and pass the function returned by `asyncAppend()` as the operation's async callback

### license

Copyright (c) 2015-2024 Jürgen Leschner, [MIT](https://opensource.org/licenses/MIT) license

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