Concurrent Executions of The Same Server Action

I have a server action which calls an external service to send and email and writes multiple records to the database. Overall it takes around 3 seconds to run.

I would like a user to be able send an email to one contact and while the server action for that is still running, send an email to another contact (using the same server action). However this doesn’t work and both server actions fail.

Is there a solution to this dilemma?

Am using PHP and MySQL.

So why not add two send mail steps in your server action?

Because the user could click on any number of [send] (paper plane) icons while the first server action is executing.

The user interface looks as below.

In the ideal world, I would like the user to be able to click, for example, on all 4 of the [send] icons in a column within the 3 seconds it takes for just the first server action to execute!

I assume that the list is generated with a repeater. So why not place the server connect component inside the repeat, you then have a server connect per item in the list.

4 Likes

Ooohhhh! Changed my world! Did not know you could do that…

2 Likes

Changed my world too! :slight_smile:

Thank you @patrick!

So @patrick… we are basically saying that we can have the same Server Action with any number of Server Connects, and the different Server Connects can all run concurrently?

So to give an example of what Patrick is saying…

If you have a server action X, then on the HTML side you will have a Server Connect, let’s call it sc_X.

If you try to call this twice at about the same time, the first call will have to finish before the second one can start.

If you define two Server Connects, sc_X1 and sc_X2, which both execute server action X, then they will execute concurrently.

When you have a repeat which contains the code with a button to execute X, then if you put the Server Connect line INSIDE the repeat, then you effectively have one Server Connect for each item repeated. Then they will operate concurrently if you click the buttons rapidly.

1 Like