1.2.2 • Published 6 years ago

async-iterator-muxer v1.2.2

Weekly downloads
3
License
MIT
Repository
-
Last release
6 years ago

async-iterator-muxer

Mux/multiplex together multiple sync and async iterables or iterators into one async iterator.

Usage

  1. Create a new instance
  2. Call .add([iterable]) to add iterable things
  3. Iterate over the muxer
  4. Optionally, .add more iterables
  5. Optionally, call .done.get([iterable]) to see it's final result (if applicable)
import AsyncIteratorMuxer from "async-iterator-muxer"
var muxer= new AsyncIteratorMuxer()

// ....

// add some sync & async iterables
muxer.add( myAsyncIterable)
muxer.add( myIterable)
muxer.add( anotherIterable)
// can also add a promise that resolves to something iterable
muxer.add( Promise.resolve([ 4, 5, 6])

// iterate through all outputs as they arrive
for await( var output of muxer){ // for-await must be run inside an async-function, not shown here
	console.log( output)
}
muxer.dones.get( myAsyncIterable) // get the return value of myAsyncIterable

Please see ./.example/sample-generator.js for a more complete, runnable, well-explained demonstration: it begins multiple asynchronous generators and multiplexes them together into one async iterable.

There's a variety of hooks and modes available, for coercing values during iteration.

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago