I have a cloud function that gets an id from the server, and increments the one kept on the server "NextId", so that the next time this function is called, it should return another id.
If the time between the calls is large enough, it seems that it always works as expected. If I call this function with small delays (even like 3 seconds) it starts to sometimes return the same value (approx 50% of the times). I'm not sure, but it seems like the first call hasn't completed updating the server field before the next call reads i? Maybe.
When I tried calling it five times with 0.5 seconds in between, i got: 46, 47, 48, 47, 48 (so yeah, even going backwards sometimes)
I'm not sure if my syntax is wrong (javascript is outside my comfort zone), or if there's a limitation of how fast the server can handle the calls? Is there any way I can make it so I'm garantueed to get a new id on every call?
handlers.requestId = function (args, context) { var dataArray = server.GetTitleInternalData({ Keys: ["NextId"] }); var idString = dataArray.Data["NextId"]; var id = parseInt(idString); var nextId = id + 1; server.SetTitleInternalData({ Key: "NextId", Value: nextId }); return { Id: id }; }