On my dedicated server, I want to make an API call, then run some code on the result. I'm working with the C# SDK.
Using async/await, this code works fine:
var result = await PlayFabAPI.Call();
// do stuff // I can return the result to the caller
However, it gets more complicated because I want to introduce an "API Queue" which runs only up to 10x api calls a second, to stay within the PlayFab API rate limits for dedicated servers. It also retries API calls if they fail due to throttling (something like exponential backoff).
The only way I can currently think of doing it is like follows:
Action<string> whenApiCallFinished = (result) => { // do stuff }; AddToAPIQueue(() => { var result = PlayFabAPI.Call(); whenApiCallFinished(result); }); // I now have no way to return the result to the caller
However, this feels hacky because now I am mixing in callbacks with async/await. My immediate question is: is it possible to do this API Queue logic with pure async/await instead of callbacks?
My broader question is: is this a good approach to trying to stay within PlayFab limits? I'm very open to changing my approach if you guys have a better solution. I figured I'd ask about the broader question before spending more hours figuring out the immediate question.
If my approach is good, then I would appreciate any guidance on the immediate question as well.