yieldmachine icon indicating copy to clipboard operation
yieldmachine copied to clipboard

Support subscribing to an EventSource

Open RoyalIcing opened this issue 4 years ago • 1 comments

  • https://www.html5rocks.com/tutorials/eventsource/basics/
const machine = start(Machine);
const eventSource = new EventSource();

machine.receiveFrom(eventSource);

const messagesKey = Symbol("messages");

function* Machine() {
  yield listenTo(eventSource, "open");
  yield on(new Map([["type", "error"], ["readyState", EventSource.CLOSED]]), Closed);

  function* Open() {
    yield listenTo(eventSource, "message");
    yield accumulate("message", messagesKey);
  }
  function* Closed() {}
  
  return function* Initial() {
    yield listenTo(eventSource, "open");
    yield on("open", Open);
  }
}

RoyalIcing avatar Feb 06 '21 04:02 RoyalIcing

This is implemented. It does seem to run in an infinite loop, re-opening after it closes.

RoyalIcing avatar Sep 16 '21 04:09 RoyalIcing