classes-2-new-in-fanout.ts 843 B

123456789101112131415161718
  1. // `new` inside a fan-out body: one Judge instance per element, all conflated into the
  2. // class's single abstract instance. Element taint enters through the ctor param
  3. // (this.item = x) and the per-element ask must see both the producer and the fan-out.
  4. // Expected: source -> ask#1; ask#1 -> fan-out#1; ask#1 -> ask#2 and fan-out#1 -> ask#2
  5. // (via this.item); ask#2 -> join#1 (and ask#1/fan-out#1 -> join#1, additive relay);
  6. // join#1 -> sink and ask#2 -> sink (return derives from the joined verdicts).
  7. const list = await agent("planner").ask<string[]>("list items");
  8. class Judge {
  9. item: string;
  10. constructor(x: string) {
  11. this.item = x;
  12. }
  13. go(): Node<string> {
  14. return agent("judge").ask<string>(`judge ${this.item}`);
  15. }
  16. }
  17. const verdicts = await Promise.all(list.map((it) => new Judge(it).go()));
  18. return verdicts.join(",");