These are just some utilities for whatwg-streams, for example to make things like csp-style programming easier.
Most of the functions herein are generator functions that yield Promises. So use them in conjunction with a Promise-supporting coroutine library such as awaitable or co.
- dealing with closed or errored streams
- listen(EventEmitter)
- figure out how to do transducer stuff nicely with these streams
This will take a value from the stream. The function will block (via Promise) until a value becomes available, but will fetch a queued value synchronously.
Example:
var val = yield* take(ch);Given an array of streams, this will return the value of the first readable stream. Note that this will try to read the streams in order.
Example:
var [ch, val] = yield* select([a, b, c]);
if (ch == a) {
// val came from channel a
} else if (ch == b) {
// val came from channel b
} // and so on…This will drain the internal queue of a readable stream. This is useful if you have an event stream that you want to listen to, but you are only interested in fresh events, and not old ones from the queue.
Example:
drain(events);
var ev = yield* take(events);This will create a ReadableStream from the events of an EventEmitter
Example:
var moves = listen(document, 'mousemove');
while (true) {
var e = yield* take(moves);
}GPLv3