# waitwait

> Golang's `WaitGroup` and Unix's `sleep` for Javascript (browser and Node.js).

Latest version **0.4.0** (published 2025-01-25) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2025-01-25 |
| First published | 2021-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Nicolas Talle |
| Maintainers | nicolab |
| Keywords | async, sync, waitgroup, sleep, promise, go, wg |

## Links

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

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.4.0 (latest) — 2025-01-25
- 0.0.4 — 2025-01-25
- 0.3.0 — 2022-10-10
- 0.2.1 — 2022-04-08
- 0.2.0 — 2022-04-08
- 0.1.1 — 2021-12-27
- 0.1.0 — 2021-12-27

## README

# WaitWait

> WIP

Tiny implementation of Golang's `WaitGroup` and Unix's `sleep` for Javascript (browser and Node.js), with promises and zero dependencies.

## Install

With NPM:

```sh
npm install waitwait --save
```

or with Yarn:

```sh
yarn add waitwait
```

or with pnpm:

```sh
pnpm add waitwait
```

or your favorite package manager...

## Usage

### Sleep

sleep (wait) 1 seconde:

```js
import { sleep } from 'waitwait';

console.log('Start');

await sleep(1000);

console.log('End');
```

### WaitGroup

Waits until the routine is done:

```js
import { WaitGroup } from 'waitwait';

const wg = new WaitGroup();

wg.add();

console.log('Start');

setTimeout(() => {
  wg.done();
}, 1000);

await wg.wait();

console.log('End');
```

---

Waits until all routines are done:

```js
import { WaitGroup } from 'waitwait';

const wg = new WaitGroup();

wg.add(2);

console.log('Start');

setTimeout(() => {
  wg.done();
}, 1000);

setTimeout(() => {
  wg.done();
}, 4000);

await wg.wait();

console.log('End');
```

---

Waits forever:

```js
import { WaitGroup } from 'waitwait';

const wg = new WaitGroup();

console.log('Start');

wg.add();

console.log('This process is running forever');

await wg.wait();

console.log('End');
```

---

Cancel a `WaitGroup`:

```js
import { WaitGroup } from 'waitwait';

const wg = new WaitGroup();

// Add 10 routines
wg.add(10);

console.log('Start');

// Cancel all routines after 2 secondes
setTimeout(() => {
  wg.cancel();
}, 2000);

await wg.wait();

console.log('End');
```

## LICENSE

[MIT](https://github.com/Nicolab/waitwait/blob/master/LICENSE) (c) 2021, Nicolas Tallefourtane.

## Author

| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://nicolab.net) |
|---|
| [Nicolas Talle](https://nicolab.net) |
| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |

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