You should check for timeout by using scala.concurrent.Future.recover or scala.concurrent.Future.recoverWith
and checking for scala.concurrent.TimeoutException:
val future = myService.calculateWithTimeout(100 millis).recover {
case _: TimeoutException =>
-1
}
Low priority implicits to add
withTimeout
methods to scala.concurrent.Future.You can dependency inject the ActorSystem as follows to create a Future that will timeout after a certain period of time:
You should check for timeout by using
scala.concurrent.Future.recover
orscala.concurrent.Future.recoverWith
and checking for scala.concurrent.TimeoutException: