order-promise-into-helper.ts 685 B

12345678910111213
  1. // A promise passed INTO a helper and awaited there. The helper is inlined at its call
  2. // site, so the barrier lands at the right point in time; the awaited expression is a
  3. // parameter, which issues nothing, so it widens exactly like a stored promise. The
  4. // trailing ask is what makes the widened barrier visible as a `maybe` edge.
  5. async function settle(p: Node<string>): Promise<string> {
  6. return await p;
  7. }
  8. const worker = agent("worker");
  9. const pending = worker.ask<string>("work");
  10. const other = await agent("other").ask<string>("other");
  11. const done = await settle(pending);
  12. const summary = await agent("summarizer").ask<string>("wrap up");
  13. return `${done} ${other} ${summary}`;