#I'm calling an api and would really like to ensure that I dont exceed ratelimit.

5 messages · Page 1 of 1 (latest)

buoyant zenith
#

When I wrote this in go I used a go routine as a spawner and would spawn api keys and put them into a channel at an interval that would most likely not exceed the rate limit. This had the added benefit that any other goroutine looking to call the api would be blocking until there was an available apikey and I could have multiple spawners putting in diff api keys (they're rate limited by key not ip). I did have to flush them every minute or so if they wernt being used... overall not sure that was the best system but I liked it.

I guess whats the most idiomatic way to do something like this?

I'm not tied to channels or even threads and workers really jsut wanna ensure that every call to the api is appropriately spaced such that it doesnt crater an api key.

Thanks, qez

flat garnet
#

an async channel delivering api keys sounds like a fine way to do that

#

if you want to be really fancy, you can wrap the individual keys such that when they're dropped they automatically go back into the rate limiter — this is a way to ensure none are lost due to bugs in the code sending the requests

buoyant zenith
#

okay I'll take a look at channels in rust I've not touched those yet

#

tyv