[whatwg/streams] Broadcast ReadableStream (#481)

I see no documentation about a kind of broadcast-focused ReadableStream. I'm thinking for example on a stream for DOM events:

    function streamFromEvent(element, eventName) {
      return new ReadableStream(new class {
        constructor() {
          this._listener = this.listener.bind(this);
        }
        listener(event) {
          this._controller.queue(event);
        }
        start(controller) {
          this._controller = controller;
          element.addEventListener(eventName, this._listener, true);
        }
        cancel() {
          element.removeEventListener(eventName, this._listener, true);
        }
      });
    }
    
    let keyDown = streamFromEvent(document, 'keydown');
    let click = streamFromEvent(document, 'click');
    merge(keyDown, click).pipeTo(userActionsLogger());

This kind of stream can be read by multiple consumers at the same time (since in this case it's infinite) and should drop the chunk immediately after execution (maybe `enqueue` is not a proper name for this operation?).

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/481

Received on Monday, 18 July 2016 20:34:47 UTC