generator-forof.ts 457 B

123456789101112
  1. // Generator yields tainted values, consumed by for...of. The yielded operand must
  2. // enter the generator's return summary so `pieces(s)` carries s's taint into the
  3. // fan-out and the per-element worker ask.
  4. function* pieces(seed: string): Generator<string> {
  5. yield `${seed}-a`;
  6. yield `${seed}-b`;
  7. }
  8. const s = await agent("s").ask<string>("seed");
  9. for (const item of pieces(s)) {
  10. await agent("worker").ask<string>(`process ${item}`);
  11. }
  12. return "done";