@gartz/iterable-stream

1.0.1 • Public • Published

IterableStream

The first for-await...of stream implementation, IterableStream lib returns a PromiseStream that is easy to subscribe, fork, pipe, and debug.

If you are having hard times with Stream API and Observables, going crazy with RxJS and BaconJS methods and complex debugging, this is the lib for your team. It's so simple that any engineer can write streams, test, and deploy great reactive applications.

Setup guide

npm install @gartz/iterable-stream

or

yarn install @gartz/iterable-stream

then include it:

import IterableStream from '@gartz/iterable-stream';

Create a stream

The function IterableStream have two params: callbackFunction(input, enqueue, close) and input.

Callback arguments:

  • input is the ref to the 2nd argument from IterableStream
  • enqueue is a Function that will add a value to the stream
  • close is a Function that should be called when the stream is closed

Example:

const myIterableStream = IterableStream(async (input, enqueue, close) => {
  enqueue('this');
  enqueue('is');
  enqueue('simple');
  close()
});

This stream will output: "this", "is", "simple"

Reading a stream

Create an async function and use for async.

async function printMyIterableStream(iterableStream) {
  for async (const value of iterableStream) {
    console.log(value);
  }
}

printMyIterableStream(myIterableStream);
// Output:
//  this
//  is
//  simple

API

A IterableStream will return a object that expose the stream, the object also have a public API that facilitate the criation of new streams with data.

Motivation

I want to create something that is simple but at same time powerful using the edge ES19 specifications.

This lib uses Promises and Generators to take full advantage of JavaScript, the code is tiny, therefore it's very powerful.

This project is inspired by:

This project implements:

Both designs are very interesting, but somewhat hard to implement and debug.

Package Sidebar

Install

npm i @gartz/iterable-stream

Weekly Downloads

5

Version

1.0.1

License

SEE LICENSE IN LICENSE

Unpacked Size

103 kB

Total Files

24

Last publish

Collaborators

  • gartz