Package

play.api.libs

concurrent

Permalink

package concurrent

Visibility
  1. Public
  2. All

Type Members

  1. class ActorRefProvider[T <: Actor] extends Provider[ActorRef]

    Permalink

    Provider for creating actor refs

  2. class ActorSystemProvider extends Provider[ActorSystem]

    Permalink

    Provider for the actor system

    Provider for the actor system

    Annotations
    @Singleton()
  3. trait AkkaComponents extends AnyRef

    Permalink

    Components for configuring Akka.

  4. trait AkkaGuiceSupport extends AnyRef

    Permalink

    Support for binding actors with Guice.

    Support for binding actors with Guice.

    Mix this trait in with a Guice AbstractModule to get convenient support for binding actors. For example:

    class MyModule extends AbstractModule with AkkaGuiceSupport {
      def configure = {
        bindActor[MyActor]("myActor")
      }
    }

    Then to use the above actor in your application, add a qualified injected dependency, like so:

    class MyController @Inject() (@Named("myActor") myActor: ActorRef) extends Controller {
      ...
    }
  5. class ExecutionContextProvider extends Provider[ExecutionContextExecutor]

    Permalink

    Provider for the default execution context

    Provider for the default execution context

    Annotations
    @Singleton()
  6. trait InjectedActorSupport extends AnyRef

    Permalink

    Support for creating injected child actors.

  7. trait LowPriorityTimeoutImplicits extends AnyRef

    Permalink

    Low priority timeouts to add withTimeout methods to scala.concurrent.Future.

  8. class MaterializerProvider extends Provider[Materializer]

    Permalink

    Provider for the default flow materializer

    Provider for the default flow materializer

    Annotations
    @Singleton()
  9. trait Timeout extends AnyRef

    Permalink

    This trait is used to provide a non-blocking timeout on an operation that returns a Future.

    This trait is used to provide a non-blocking timeout on an operation that returns a Future.

    Please note that the play.api.Application default ActorSystem should be used as input here, as the actorSystem.scheduler is responsible for scheduling the timeout, using akka.pattern.actor under the hood.

    You can dependency inject the ActorSystem as follows to create a Future that will timeout after a certain period of time:

    class MyService(val actorSystem: ActorSystem) extends Timeout {
    
      def calculateWithTimeout(timeoutDuration: FiniteDuration): Future[Int] = {
        timeout(actorSystem, timeoutDuration)(rawCalculation())
      }
    
      def rawCalculation(): Future[Int] = {
        import akka.pattern.after
        implicit val ec = actorSystem.dispatcher
        akka.pattern.after(300 millis, actorSystem.scheduler)(Future(42))(actorSystem.dispatcher)
      }
    }

    You should check for timeout by using Future.recover() or Future.recoverWith() and checking for TimeoutException:

    val future = myService.calculateWithTimeout(100 millis).recover {
      case _: TimeoutException =>
        -1
    }
    See also

    Futures and Promises

Value Members

  1. object ActorSystemProvider

    Permalink
  2. object Akka

    Permalink

    Helper to access the application defined Akka Actor system.

  3. object Execution

    Permalink
  4. object Promise

    Permalink

    useful helper methods to create and compose Promises

  5. object Timeout extends Timeout with LowPriorityTimeoutImplicits

    Permalink

    This is a static object that can be used to import timeout implicits, as a convenience.

    This is a static object that can be used to import timeout implicits, as a convenience.

    import play.api.libs.concurrent.Timeout._

Ungrouped