Next.js Discord

Discord Forum

Server Actions: Non-Blocking Behaviour?

Unanswered
Knopper gall posted this in #help-forum
Open in Discord
Knopper gallOP
So currently, by default, server actions are blocking.
By that, I mean that if the client executes >1 server action in quick succession, they will be queued, and each action will be called in order, only when the previous action resolves.

To put this more logically, let's imagine a client does the following:
serverAction() // 1
serverAction() // 2
serverAction() // 3

action 1 is called, once that is no longer pending, action 2 is called, once that finishes, then action 3 is called

Is there a way I can opt-out of the queueing behaviour and have all these actions run asynchronously?

2 Replies

call one server actions and inside that server action call the logic that server actions 2 and 3 are calling inside of a Promise.all or Promise.allSettled
@linesofcode call one server actions and inside that server action call the logic that server actions 2 and 3 are calling inside of a Promise.all or Promise.allSettled
Knopper gallOP
I don't think we're on the same wavelength. The example was just to explain the behaviour.
The issue is the actions can be called in any sequence, at any point in time by the client, and don't depend on eachother

The queueing behaviour is done by the client, so any action called at any point in the site will "queue" the action, I don't want the action to be queued (no matter which action)