LowPriorityFuturesImplicits
play.api.libs.concurrent.LowPriorityFuturesImplicits
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:
class MyService @Inject()(piCalculator: PiCalculator)(implicit futures: Futures) {
def calculateWithTimeout(timeoutDuration: FiniteDuration): Future[Int] = {
piCalculator.rawCalculation().withTimeout(timeoutDuration)
}
}
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
}
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Futures.type
Members list
In this article