I'm using the async Play WS Scala API to query a RESTful service. I wonder how I could process a List
containing request URLs to be called via WSClient
, but not more than one request per second (the service allows "only" 1 request per second per client). From a logical standpoint, the idea is to get an element (URL) from the list, make a request, then wait a certain amount of time before proceeding with the next element in the list.
- using good old
Thread.sleep
in a non-blocking and asynchronous framework like Play is certainly a bad idea. - the same is probably true for things like
ScheduledThreadPoolExecutor
or other methods that require to spawn new threads.
How could I throttle the request rate without having a negative impact on the asynchronous and "as-less-threads-as-possible" nature of Play?