I have some code that initiates a "slow" process, which I wrap in a Future. If something goes wrong, I want to slowly loop and retry after a pause--indefinitely. Kinda like this: (I know that eventually a human will intervene and fix the problem)
def doSomething():Unit = {
aFutureThing().onComplete {
case Success(s) => println("Success: "+s)
case Failure(x) =>
// Take some (hopefully) corrective action here, call for help, etc.
Thread.sleep(1000) // pause a bit
doSomething() // and try again...
}
}
doit()
When the onComplete callback is called, is doSomething() still on the stack or has it been popped because we've returned while the Future was executing the slow task (aFutureThing)? Will this recursive calling of doSomething (eventually) blow up the stack/OutOfMemory or something? If so... is there a safer way to do retries on a Future?