play.api.libs.concurrent

Members list

Type members

Classlikes

class ActorRefProvider[T <: Actor](name: String, props: Props => Props)(implicit evidence$1: ClassTag[T]) extends Provider[ActorRef]

Provider for creating actor refs

Provider for creating actor refs

Attributes

Supertypes
trait Provider[ActorRef]
class Object
trait Matchable
class Any
@Singleton
class ActorSystemProvider(environment: Environment, configuration: Configuration) extends Provider[ActorSystem]

Provider for the actor system

Provider for the actor system

Attributes

Companion
object
Supertypes
trait Provider[ActorSystem]
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
@Singleton

Provider for a classic actor system provide

Provider for a classic actor system provide

Attributes

Supertypes
trait Provider[ClassicActorSystemProvider]
class Object
trait Matchable
class Any
@Singleton
class CoordinatedShutdownProvider(actorSystem: ActorSystem, applicationLifecycle: ApplicationLifecycle) extends Provider[CoordinatedShutdown]

Provider for the coordinated shutdown

Provider for the coordinated shutdown

Attributes

Supertypes
trait Provider[CoordinatedShutdown]
class Object
trait Matchable
class Any
abstract class CustomExecutionContext(system: ActorSystem, name: String) extends ExecutionContextExecutor

This class defines a custom execution context that delegates to an pekko.actor.ActorSystem.

This class defines a custom execution context that delegates to an pekko.actor.ActorSystem.

It is very useful for situations in which the default execution context should not be used, for example if a database or blocking I/O is being used.

To define a custom context, subclass CustomExecutionContext with the dispatcher name:

@Singleton
class DatabaseExecutionContext @Inject()(system: ActorSystem)
  extends CustomExecutionContext(system, "database-dispatcher")

and then bind it in dependency injection:

bind[DatabaseExecutionContext].to(classOf[DatabaseExecutionContext]).asEagerSingleton()

Then have the execution context passed in as an implicit parameter:

class DatabaseService @Inject()(implicit executionContext: DatabaseExecutionContext) {
 ...
}

Value parameters

name

the full path of the dispatcher name in Typesafe Config.

system

the actor system

Attributes

See also
Supertypes
trait Executor
class Object
trait Matchable
class Any
Show all
class DefaultFutures(actorSystem: ActorSystem) extends Futures

ActorSystem based timeout.

ActorSystem based timeout.

Value parameters

actorSystem

the actor system to use.

Attributes

Supertypes
trait Futures
class Object
trait Matchable
class Any
@Singleton
class ExecutionContextProvider(actorSystem: ActorSystem) extends Provider[ExecutionContextExecutor]

Provider for the default execution context

Provider for the default execution context

Attributes

Supertypes
trait Provider[ExecutionContextExecutor]
class Object
trait Matchable
class Any
trait Futures

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

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

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

class MyService @Inject()(futures: Futures, piCalculator: PiCalculator) extends Timeout {
 def calculateWithTimeout(timeoutDuration: FiniteDuration): Future[Int] = {
   futures.timeout(timeoutDuration)(piCalculator.rawCalculation())
 }
}

And you can also use a delay to return data after a given period of time.

class PiCalculator @Inject()(futures: Futures) {
 def rawCalculation(): Future[Int] = {
   futures.delay(300 millis) { Future.successful(42) }
 }
}

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

See also
Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Futures.type

Support for creating injected child actors.

Support for creating injected child actors.

Attributes

Supertypes
class Object
trait Matchable
class Any

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

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

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Futures.type
@Singleton
class MaterializerProvider(actorSystem: ActorSystem) extends Provider[Materializer]

Provider for the default flow materializer

Provider for the default flow materializer

Attributes

Supertypes
trait Provider[Materializer]
class Object
trait Matchable
class Any
object Pekko

Helper to access the application defined Pekko Actor system.

Helper to access the application defined Pekko Actor system.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Pekko.type

Components for configuring Pekko.

Components for configuring Pekko.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
@Singleton
class PekkoSchedulerProvider(actorSystem: ActorSystem) extends Provider[Scheduler]

Provider for an Pekko Typed Scheduler.

Provider for an Pekko Typed Scheduler.

Attributes

Supertypes
trait Provider[Scheduler]
class Object
trait Matchable
class Any

Pekko Typed components.

Pekko Typed components.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes