t

play.api.libs.concurrent

LowPriorityFuturesImplicits

trait LowPriorityFuturesImplicits extends AnyRef

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
}
Source
Futures.scala
Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LowPriorityFuturesImplicits
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. implicit class FutureOps[T] extends AnyRef