I have a code similar to this:
for (n <- 1 to 1000) {
someFuture map {
// some other stuff
}
This is a basic piece of code and works fine. However, somefuture
does some queries to a database, and the database cannot receive several queries in parallel, which is what happens before (it spawns a lot of threads executing somefuture
as one would expect).
Ideally, I would like to do it sequentially (i.e. call someFuture
when n=1, do some processing, call someFuture
when n=2, do some processing, etc). I thought about using some blocking method (from Await
) but this happens inside an actor, so blocking is not a good idea. Another idea was creating a fixed thread pool for this particular future call, but sounds like overkill. What should I do instead?
Update: I have found this answer which suggests creating a fixed thread pool as I thought. Still, is this the right way to do it?