shared-helper-param-each.ts 616 B

1234567891011
  1. // A parameter handed to a per-element library call: `xs.map(fn)` inside `each` is one
  2. // fan-out site reached from both calls, and each call's activation inlines only its own
  3. // callback inside that fan-out. Both asks are within fan-out#1: they run per element of the
  4. // one map site.
  5. async function each(xs: string[], fn: (x: string) => Promise<string>): Promise<string[]> {
  6. return Promise.all(xs.map(fn));
  7. }
  8. const ids = ["1", "2"];
  9. const a = await each(ids, async (x) => agent(`a-${x}`).ask<string>(`a ${x}`));
  10. const b = await each(ids, async (x) => agent(`b-${x}`).ask<string>(`b ${x}`));
  11. return [...a, ...b];