Dev Helpers
← Back

Sequence asynchronous typed work

Sequence asynchronous typed work using TypeScript.

Open this example in the interactive library

Source code

const load = async (id: number): Promise<{ id: number; ready: boolean }> => ({
  id,
  ready: true,
});
console.log(
  await (async () => {
    const ids: number[] = [];
    for (const n of [2, 1]) ids.push((await load(n)).id);
    return ids;
  })(),
);

Sample output

[ 2, 1 ]