Home

Awesome

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 consumable-stream

Usage

The ConsumableStream class exposes the following methods:

// 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);
})();