async-promise-then-both-callbacks.ts 585 B

123456789101112
  1. // .then with BOTH callbacks plus a .finally in the chain: either callback's ask
  2. // result becomes the settled value, and .finally passes it through.
  3. // Expected: ask#1 -> ask#2 (draft into the fulfill callback, inexact ok);
  4. // ask#2 -> sink; ask#3 -> sink (both callbacks' results may settle the chain).
  5. const draft = agent("writer").ask<string>("draft");
  6. const settled = await Promise.resolve(draft)
  7. .then(
  8. (t) => agent("editor").ask<string>(`edit ${t}`),
  9. (e) => agent("fixer").ask<string>(`recover from ${String(e)}`),
  10. )
  11. .finally(() => log("done"));
  12. return settled;