# @socket-mesh/consumable-stream

> A readable async stream which can be iterated over using a for-await-of loop.

Latest version **3.3.3** (published 2026-04-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @socket-mesh/consumable-stream
pnpm add @socket-mesh/consumable-stream
yarn add @socket-mesh/consumable-stream
bun add @socket-mesh/consumable-stream
```

## Health

**Score 60/100 (C)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.3.3 |
| Published | 2026-04-11 |
| First published | 2023-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jonathan Gros-Dubois |
| Maintainers | gak10100 |
| Keywords | async, generator, stream, data, for-await-of |

## Links

- npm: https://www.npmjs.com/package/@socket-mesh/consumable-stream
- Repository: https://github.com/socket-mesh/consumable-stream
- Issues: https://github.com/socket-mesh/consumable-stream/issues
- npm.io page: https://npm.io/package/@socket-mesh/consumable-stream

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@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

## Recent versions

- 3.3.3 (latest) — 2026-04-11
- 3.3.2 — 2025-11-12
- 3.2.1 — 2023-10-02
- 3.2.0 — 2023-03-31
- 3.1.1 — 2023-03-30
- 3.1.0 — 2023-03-28
- 3.0.0 — 2023-03-28

## README

# consumable-stream
A readable stream which can be iterated over using a for-await-of loop or using a while loop with await inside.

The `ConsumableStream` constructor is an abstract class which must be subclassed. Its `next()` and `createConsumer()` methods must be overriden.

For a concrete subclass of `ConsumableStream`, see `WritableConsumableStream`: https://github.com/SocketCluster/writable-consumable-stream

## Installation

```
npm install @socket-mesh/consumable-stream
```

## Usage

The `ConsumableStream` class exposes the following methods:

- `[Symbol.asyncIterator]`: Makes the instance iterable using a for-await-of loop.
- `next`: Returns a `Promise` which will resolve an object in the form `{value: data, done: boolean}` whenever some data is received or when the stream ends.
- `once`: Similar to `next()` except that the resolved value will be the raw data and it will not resolve when the stream ends. Note that once `once()` is called, it cannot be cancelled; the affected closure will stay in memory until either `once()` resolves or until the stream is ended or garbage collected.

```js
// Consume data objects from consumableStream as they are written to the stream.
(async () => {
  for await (let data of consumableStream) {
    console.log(data);
  }
})();

// Consume only the next data object which is written to the stream.
(async () => {
  let data = await consumableStream.once();
  console.log(data);
})();
```

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