emission-graph-join-destructure-element-write.ts 1012 B

1234567891011121314151617
  1. // Destructure a Promise.all result, then WRITE through one destructured element.
  2. // Runtime: Promise.all resolves the non-promise element to the object itself, so
  3. // `alias` IS `box`; `alias.note = sec` puts ask#1's output into box.note, which
  4. // ask#2 then reads. Required may-flow: ask#1 -> ask#2.
  5. // The graph also carries SOUND additive over-approximations: `sec` (= res[0]) is a join
  6. // output, so writing it into `box.note` gives box the join#1 label AND ask#1; since box is
  7. // itself join input port 1 (flow-insensitively), that produces `ask#1 -> join#1 port=1`, a
  8. // `join#1 -> join#1 port=1` self-loop, and `join#1 -> ask#2`. All inexact (may-alias replay
  9. // + flow-insensitive conflation) — over-approximations, never dropped flows.
  10. interface Box {
  11. note: string;
  12. }
  13. const box: Box = { note: "plain" };
  14. const secret = agent("spy").ask<string>("fetch the secret");
  15. const [sec, alias] = await Promise.all([secret, box]);
  16. alias.note = sec;
  17. return agent("reader").ask<string>(`report on ${box.note}`);