Runs the given tasks in a sequence.

Type signature

(
  tasks: {
    (): Promise<any>;
  }[]
) => Promise<any[]>

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