async-promise-custom-thenable.ts 418 B

1234567891011
  1. // Custom thenable: `await thenable` invokes its then() method, which forwards the
  2. // draft's resolved output into the continuation callback -> text.
  3. // Expected: ask#1 -> ask#2 data; ask#2 -> sink.
  4. const draft = agent("writer").ask<string>("draft");
  5. const thenable = {
  6. then(onOk: (v: string) => void) {
  7. draft.then(onOk);
  8. },
  9. };
  10. const text = await thenable;
  11. return agent("editor").ask<string>(`edit: ${text}`);