I want to prevent concurrency on cloudscript functions call.
For example, I created one cloudscript function name claimDailyRewards, which gives users a daily reward item in their inventory.
Now, if one user tries to cheat and call this function many times concurrently by using rest API, then that user can get multiple rewards. I want to prevent this to happen.
I think it would be great if this can be manage with some sort of key value pair where you can update and get old value in return in same API call.
Suppose user A tries to cheat and call function multiple time concurrently.
In cloudscript function, i will first call update method and set it to true and it gives me undefined value in response.
So for 1st request it will mark dailRewardClaim key to true. and continue its execution
meanwhile 2nd concurrent request come, it will mark dailyRewardClaim to true but in response it will get true value as 1st request already updated it. so it return error.
Now, 1st request finished its execution and delete dailyRewardClaim key.
This way we can prevent concurrency easily. I am not sure about this so i asked question here and not created any feature request.
Is it possible? if not then is there any other way?