Runs the given tasks in a sequence.

Type signature

<T>(tasks: Task<T>[]) => Promise<Awaited<T>[]>

Examples

const f = () =>
  new Promise((resolve) =>
    setTimeout(resolve, 1000),
  );
const g = () =>
  new Promise((resolve) =>
    setTimeout(resolve, 2000),
  );

sequence([f, g]).then(() =>
  console.log("Done"),
);
Try in REPL

Questions

  • How to run async tasks sequentially?

TypeScript sourceJavaScript source