How to rate limit function call in a loop in Scala
The following code do a bunch of calls to an external API. This API does
not allow more than 3 queries per second. syncCallToApi is a function
provided by the api client library that do a synchronous request and
returns the result. I can't modify this function.
What is the best way in Scala to concurrently call callToApi no more than
3 times per seconds while keeping the following semantics:
val ids = Seq(12980,2932,3441,42334,980,32,4531,7234) // start with a seq
en ids
val results: Seq[Item] = ids.map(id => syncCallToApi(id)) // ...
println(results) // end with a seq of results
No comments:
Post a Comment