strand-then-internal-await.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233
  1. // A `.then` continuation that awaits inside itself, registered and only later awaited
  2. // through the variable it was bound to. The continuation is a deferred strand: its first
  3. // event is the ordinary barrier over its receiver (the writer's ask), and the edit it awaits
  4. // belongs to the strand's frame, never to the main line.
  5. //
  6. // This is the "edge disappears" case the plan predicted and no existing fixture has: the
  7. // side ask is issued between the registration and `await q`, and under the old global
  8. // `settle maybe` it collected a `seq maybe` arrow from the receiver's step. It gets none now.
  9. //
  10. // The join at `await q` is the bound-variable half of the awaited-position scan: `q` is the
  11. // operand, `strandsBySymbol` holds the strand spawned while its declaration was evaluated,
  12. // and the strand's summary carries BOTH the receiver's step (settled by the prologue) and
  13. // the editor's (settled by the callback's own await).
  14. //
  15. // Expected:
  16. // core — `region call#1 call parent=seq#1>choice#1>branch#1 … label="then" strand` (the
  17. // continuation runs iff the receiver fulfils, hence the skippable choice), a CERTAIN
  18. // `settle ask#1` prologue inside it, `settle ask#2` inside it too, `settle ask#3 in=seq#1`
  19. // for the side ask, and `settle ask#1,ask#2 in=seq#1 joins=call#1` at `await q`.
  20. // causality — `ask#1 -> ask#2 data` (the draft feeds the edit) and NO edge from either
  21. // ask#1 or ask#2 into ask#3.
  22. // cfg — `ask#2@1 -> sink join via=return`: the editor's ask leaves by the barrier at
  23. // `await q`, which is the last node, not by the sequential line through the side ask.
  24. // `ask#1@1 -> ask#3@1 branch` is the skip arm of the choice, the main line walking past
  25. // a continuation that may never run.
  26. const p = agent("w").ask<string>("draft");
  27. const q = p.then(async (t) => {
  28. const e = await agent("e").ask<string>("edit " + t);
  29. return e;
  30. });
  31. const side = await agent("s").ask<string>("side");
  32. const out = await q;
  33. return out + side;