iteration-fanout-generator-of-asks.ts 834 B

12345678910111213141516
  1. // A generator yielding ASK NODES (not strings), consumed by for...of whose body only
  2. // awaits and collects (no facade call in the body -> the for...of must NOT promote).
  3. // The yields join the generator's summary, so jobs(s) carries ask#1/ask#2; awaiting
  4. // the elements and pushing into results routes both into ask#3's instructions.
  5. // Expected: source -> world-read#1; world-read#1 -> ask#1, world-read#1 -> ask#2;
  6. // ask#1 -> ask#3, ask#2 -> ask#3 (MUST); ask#3 -> sink; NO fan-out node.
  7. function* jobs(seed: string): Generator<Node<string>> {
  8. yield agent("a").ask<string>(`one ${seed}`);
  9. yield agent("b").ask<string>(`two ${seed}`);
  10. }
  11. const s = await files.read("seed.txt");
  12. const results: string[] = [];
  13. for (const job of jobs(s)) {
  14. results.push(await job);
  15. }
  16. return agent("c").ask<string>(results.join(","));