Message Generators

Send: yield "some string" Receive: const reply = yield "string" Result: return "final message"
function* GenerateSomething() {
  // Send a message.
  yield "abc";

  // A message can be a primitive: string, number, regex, symbol.
  yield "abc";
  yield 42;
  yield /[a-z]+/;
  yield Symbol.for("identifier");

  // A message can be a collection: array, set, map, object.
  yield ["abc", "def"];

  // A message can be another generator function.
  yield OtherGenerator;

  // Receive a message reply.
  const reply = yield "abc";

  // Return a final message.
  // You can use the result of replies!
  return { a: "final result", b: reply };
}