# @vates/generator-toolbox

Latest version **1.1.3** (published 2026-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @vates/generator-toolbox
pnpm add @vates/generator-toolbox
yarn add @vates/generator-toolbox
bun add @vates/generator-toolbox
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2026-06-24 |
| First published | 2025-02-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=20.18 |
| Dependencies | 0 |
| Unpacked size | 14.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 989 |
| Author | Vates SAS |
| Maintainers | mpiton, florent.beauchamp, mathieura, julien-f, marsaud, pdonias, tgoettelmann, enishowk, b-nollet, mlssfrncjrg, arnogues, joris-k, elise-f, nathanael-h, olivier.f, pierre.brunet289 |

## Links

- npm: https://www.npmjs.com/package/@vates/generator-toolbox
- Repository: https://github.com/vatesfr/xen-orchestra
- Homepage: https://github.com/vatesfr/xen-orchestra/tree/master/@vates/generator-toolbox
- Issues: https://github.com/vatesfr/xen-orchestra/issues
- npm.io page: https://npm.io/package/@vates/generator-toolbox

## Recent versions

- 1.1.3 (latest) — 2026-06-24
- 1.1.2 — 2026-04-24
- 1.1.1 — 2026-03-27
- 1.1.0 — 2025-10-27
- 1.0.4 — 2025-07-28
- 1.0.3 — 2025-06-05
- 1.0.2 — 2025-05-23
- 1.0.1 — 2025-02-24

## README

<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->

# @vates/generator-toolbox

[![Package Version](https://badgen.net/npm/v/@vates/generator-toolbox)](https://npmjs.org/package/@vates/generator-toolbox) ![License](https://badgen.net/npm/license/@vates/generator-toolbox) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/generator-toolbox)](https://bundlephobia.com/result?p=@vates/generator-toolbox) [![Node compatibility](https://badgen.net/npm/node/@vates/generator-toolbox)](https://npmjs.org/package/@vates/generator-toolbox)

## Install

Installation of the [npm package](https://npmjs.org/package/@vates/generator-toolbox):

```sh
npm install --save @vates/generator-toolbox
```

## Usage

A toolbox to ease the use of generator

### Timeout

wrap a source async generator to have it throw an error when timeout is reached
timeout is a positive number in milliseconds

```js
import { Timeout } from '@vates/generator-toolbox'

const wrappedGenerator = new Timeout(sourceGenerator, timeout)
```

### Throttle

wrap a source async generator to have it respect a max speed ( in bytes per seconds).
speed is either a strictly positive number or a function returning a strictly positive number. A speed change will be used for the next emitted packet.

The source generator must yield object with a length property.

Optimized for small yields regarding to the speed, since it won't split incoming packet.

If the generator reached the max speed it will be paused, limiting memory consumption.

```js
import { Throttle } from '@vates/generator-toolbox'

const wrappedGenerator = new Throttle(sourceGenerator, speed)
```

### Synchronized

Fork a generator. The rules are:

- if the source returns, all the forks return
- if the forks error, all the forks error with the same error
- if a fork returns, it is stopped, but the generator continue with the other
- if a fork errors, it is stopped, but the generator continue with the other
- if all the forks return, the source is stopped
- if all the forks error, the source is errored with the last error
- the source start producing a packet when the fastest forked ask for it
- the source forks get the packet only when all the forks asked for it, no buffer stores in memory

```ts
import { Synchronized } from '@vates/generator-toolbox'

async function consume(generator: AsyncGenerator) {
  for await (const val of generator) {
    console.log({ val })
  }
}
const forker = new Synchronized(generator)
const first = forker.fork('first')
const second = forker.fork('second')
await Promise.all([consume(first), consume(second)])
```

Note: you can stop early a generator by calling `generator.return()`, and you can stop in in error by calling `generator.throw(error)`

## Contributions

Contributions are _very_ welcomed, either on the documentation or on
the code.

You may:

- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
  you've encountered;
- fork and create a pull request.

## License

[MIT](https://spdx.org/licenses/MIT) © [Vates SAS](https://vates.fr)

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