avivbiton / BlizzardApiReader

.Net Core library to handle Blizzard public APIs
MIT License
35 stars 36 forks source link

Asynchronously queue requests #41

Open linahanner opened 6 years ago

linahanner commented 6 years ago

Because of the rate limitation it might be nice to be able to queue a request, the request will sit in a queue and wait for its turn before being sent to the Blizzard API.

Some ideas on how this could be done...

Going to do some research and suggest a few solutions

avivbiton commented 6 years ago

Do you mean a queue that will fire a request every X seconds and hold when the request limit has reached the maximum?

linahanner commented 6 years ago

The limitation is 100 requests / seconds towards the Blizzard API.

If a request is made and the 100 request rate limit has been reached, instead of throwing an exception my suggestion is to put the request in a queue. So that, once the rate limitation has passed its duration we can immediately send the next 100 requests from the queue and return the response for those.

I haven't gotten around to creating an implementation as it fully depends on Blizzard and how they handle the rate limitation. One example is, as you suggest, having a loop which sends 100 requests every second. This loop can be triggered as soon as a request is being sent, and terminate if there are no requests remaining in the queue.

Will do a little more research to try to understand what the response from Blizzard might look like once the rate limit has been met.