# waiter

> A simple way to wait for multiple asynchronous calls to return

Latest version **0.1.1** (published 2011-04-13) · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2011-04-13 |
| First published | 2011-04-11 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.4.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Marcello Bastéa-Forte |
| Keywords | async, parallel, flow, asynchronous, flow-control, parallel |

## Links

- npm: https://www.npmjs.com/package/waiter
- Repository: https://github.com/marcello3d/node-waiter
- npm.io page: https://npm.io/package/waiter

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2011-04-13
- 0.1.0 — 2011-04-11

## README

node-waiter
===========
A simple way to wait for multiple asynchronous calls to return in Node.js.

Introduction
------------
Just a little utility class I wrote for dealing with parallel code. It lets you spin off a bunch of asynchronous
operations and wait for them to finish.

Waiter is similar to other projects like [Step][1], [async][2], and [Seq][3], but with a focus on parallel operations
that return values.

Examples
--------

Read three files asynchronously.

    var waiter = new Waiter
    var aFile = waiter(),
        bFile = waiter(),
        cFile = waiter()
    fs.readFile('a.txt', aFile)
    fs.readFile('b.txt', bFile)
    fs.readFile('c.txt', cFile)
    // wait for them to finish
    waiter.waitForAll(function(error) {
        if (error) {
            // inspect individual errors in aFile.error, bFile.error, and cFile.error
            throw "oh no!"
        }
        // do something with aFile.value, bFile.value, and cFile.value
    })

You can call waiter() as many times as you want --- but call them all before calling waitForAll!

    var files = [ ... ]
    var waiter = new Waiter

    var filesContent = files.map(function(file) {
        // Alternative syntax, pass a function into waiter(), and get the callback as an argument
        return waiter(function(done) {
            fs.readFile(file,done)
        })
    })
    waiter.waitForAll(function(error) {
        // do something with error or fileContents[x].value
    }, 2000) // optional timeout parameter


Don't care about the values? You don't have to store the result of waiter():

    var waiter = new Waiter
    fs.writeFile('a.txt', 'hello a!', waiter())
    fs.writeFile('b.txt', 'hello b!', waiter())
    fs.writeFile('c.txt', 'hello c!', waiter())
    waiter.waitForAll(function(error) {
        if (error) {
            console.error("Oh no!", error)
        } else {
            // all files have been written successfully!
        }
    })

Alternative syntax if you don't care about the values:

    new Waiter(
        function(done) {
            fs.writeFile('a.txt', 'hello a!', done)
        },
        function(done) {
            fs.writeFile('b.txt', 'hello b!', done)
        }
    ).waitForAll(function(error) {
        // same old...
    })

License
-------
Waiter is open source software under the [zlib license][1].

[1]: https://github.com/creationix/step
[2]: https://github.com/caolan/async
[3]: https://github.com/substack/node-seq
[4]: https://github.com/marcello3d/node-mongolian/blob/master/LICENSE

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