async-promise-allsettled-value.ts 676 B

1234567891011121314
  1. // Promise.allSettled: field-sensitive access through the settled records
  2. // (.value on the fulfilled arm, .reason on the rejected arm) must keep the flow.
  3. // Expected: ask#1 -> join#1 port=0; ask#2 -> join#1 port=1;
  4. // join#1 -> ask#3 port=0 and port=1; ask#1 -> ask#3; ask#2 -> ask#3 (additive);
  5. // ask#3 -> sink.
  6. const results = await Promise.allSettled([
  7. agent("alpha").ask<string>("a"),
  8. agent("beta").ask<string>("b"),
  9. ]);
  10. const r0 = results[0];
  11. const first = r0.status === "fulfilled" ? r0.value : String(r0.reason);
  12. const r1 = results[1];
  13. const second = r1.status === "fulfilled" ? r1.value : "";
  14. return agent("merger").ask<string>(`merge ${first} ${second}`);