UNPKG

rafa

Version:

Rafa.js is a Javascript framework for building concurrent applications.

30 lines (24 loc) 866 B
Return the same stream node after pushing a value or error through the stream. If value is an instance of Error, an error message is pushed, otherwise a value message is pushed. If isDone is true then a done message is also pushed. Note that using this function will not cause the stream to wait for new messages. This is simply a simple way to send one-off messages. To utilize backpressure, create a Channel or Enumerator and pass it to `enumerate()`. <aside> ```js // write(value: A | Error, isDone: Bool): Stream var stream = Rafa.stream(); var results = { vals: [] }; stream.error(e => results.err = e.message) .each(v => results.vals.push(v)) .done(v => results.last = v); stream.write({ name: "Trout" }) .write(new Error("oops")) .write(24, true); // results: // - err: oops // - vals: [{ name: "Trout" }, 24] // - last: 24 ``` </aside>