shared-helper-param-to-then.ts 509 B

123456789
  1. // A parameter handed on to a library call: `.then(fn)` inside `later` is an `argument`
  2. // application through later's parameter. Each call of `later` inlines only the callback it
  3. // passed, as a deferred strand with the receiver's barrier for a prologue.
  4. async function later(fn: () => Promise<string>): Promise<string> {
  5. return Promise.resolve("go").then(fn);
  6. }
  7. const a = await later(async () => agent("a").ask<string>("a"));
  8. const b = await later(async () => agent("b").ask<string>("b"));
  9. return [a, b];