Suppose there is a method that return future
def getSomeResult(): Future[SomeResult]
it may return different results depending when is it called, in particular I'm interested in success result from this method and want to call that method again if result is failure. I have a strong assurance that eventually that method will return success result So, I wrote next recursive function
def rec(): Future[SomeResult] = {
getSomeResult().recoverWith{case e => rec()}
}
What bad can happen using method rec()
? I suspect that StackOverflowException
is not the problem here, because future is running on different thread with its own stack. Another problem that I also suspect is that all threads in the thread pool may be busy trying to execute this future, so this is a kind of starvation, is it true?