Consider the following functions:
async function printAB() {
console.log("A");
await new Promise((resolve) => setTimeout(resolve, 1000));
console.log("B");
}
async function f() {
printAB();
printAB();
}
the usual expected output of f() would be
A
A
B
B
as the console.log('A') statements can execute concurrently with the timeouts. Indeed, this is what we get if the functions are either both on the server (actions or defined in a server component) or both on the client. However, if printAB is a server action, and f is a function in a user component, we get
A
B
A
B
. Why does this happen? This behavior could cause lower performance if we use multiple actions at once, is there a way to avoid it?
from Why are Server Actions not executing concurrently?
No comments:
Post a Comment