Mutex or a method to deal with race conditions

We have an app where we make multiple API calls to an LLM from a list of prompts. When each call returns, their response is added to a single list.

I have seen that, depending on when each call returns, often there are a few responses that don’t get added to the list due to a race condition.

I believe I need something like a mutex/lock object so I can guarantee that each add call is serialized. I had hoped that this would be implemented by bubble behind the scenes, but this isn’t the case.

What are my options here? This seems like very basic behavior for any app where updates to a list can potentially occur at the same time.

Rory

I think it’s a wrong approach in your case. Each response should be a different thing in DB. Theses responses should be linked to a specific request item. Not opposite (adding a list of response to request thing)

You can use recursive workflow. Or do as Jici has suggested, create a thing first, add it to the list, then call the LLM.