I’m running into a race condition because I’m trying to add an item if it doesn’t exist and remove it if it does. I’ve put conditions on the two actions, but the problem is that they’re not running exactly at the same time, so in some cases it’s creating the item, which makes the condition on the other action true, and it deletes it.
So it’s creating and then instantly deleting the item, or it’s deleting then instantly re-creating it.
If I could create an if/else condition, to force only running one of the conditions, then I could solve this.
For those who want to know the specifics of what I’m doing, here it is, but I’m still interested in the abstract question because even if there’s a better way to do this for this particular use-case, I still want to know in a general sense if there’s a way to force only one of the two conditions to run.
Specifics on what I want to do: I have a list of items. When you click on an item, it adds a new thing to the “bookmarks” table. If you click it again, it will remove that exact thing from the bookmarks table.
Hi there, @brenton.strine… a screenshot of your setup might help, but if I understand your post correctly, you have one workflow event that has two actions in it, and each action has a condition on it, right? If that accurately describes your setup, it doesn’t surprise me that you are running into the issue you described. One way to address the situation is to have two workflow events (each one only having one action in it), and put your conditions at the event level. With that configuration in place, you shouldn’t get into the situation you described because only one of the events will run.
I’m really interested in the details of this. What stops Bubble from running the first event, adding the item, and then looking at the condition on the second event, seeing that the item has been added, and then also running the second event?
Additionally, why does that happen if they’re in the same event, but doesn’t happen if they’re in separate events? Are event conditions guaranteed to be evaluated simultaneously?
Frontend workflow actions run in order but the next action does not wait on the previous action to be complete before triggering.
If they run “in order”, there’s a chance that one of them will complete before the next stops. That would mean that putting the conditions on the workflow would not guarantee that this problem wouldn’t occur. Am I understanding that wrong?
The bottom line (for me, at least) is that it works. However, you do have other options for “enforcing” workflows. You could make use of custom events or you could have workflow actions that use the result of a previous action to determine if/when they are run.