1 min read

NO_SERIAL_ASYNC_CALLS

Prevent blocking serial async await calls in your applications.
Table of Contents

Conformance is available on Enterprise plans

Async await calls that are executed sequentially can cause major performance issues because each await call blocks further execution until that given Promise resolves.

Instead, of executing async logic sequentially, opt to refactor the logic so it can be run parallel.

This can be achieved using Promise.all. An example of how this can be done:

export async function getStaticProps() {
  const firstThing = await getFirstThing();
  const secondThing = await getSecondThing();
 
  return {
    props: {
      firstThing,
      secondThing,
    },
  };
}

We can extract both await expressions into a single Promise.all, as follows:

export async function getStaticProps() {
  const [firstThing, secondThing] = await Promise.all([
    getFirstThing(),
    getSecondThing(),
  ]);
 
  return {
    props: {
      firstThing,
      secondThing,
    },
  };
}
Last updated on February 22, 2024