play.api.libs.concurrent
Members list
Type members
Classlikes
Provider for creating actor refs
Provider for creating actor refs
Attributes
- Supertypes
Provider for the actor system
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
ActorSystemProvider.type
Provider for a classic actor system provide
Provider for a classic actor system provide
Attributes
- Supertypes
Provider for the coordinated shutdown
Provider for the coordinated shutdown
Attributes
- Supertypes
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 ExecutionContextExecutortrait Executortrait ExecutionContextclass Objecttrait Matchableclass AnyShow all
ActorSystem based timeout.
ActorSystem based timeout.
Value parameters
- actorSystem
-
the actor system to use.
Attributes
- Supertypes
Provider for the default execution context
Provider for the default execution context
Attributes
- Supertypes
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 Objecttrait Matchableclass Any
- Known subtypes
-
class DefaultFutures
Attributes
Support for creating injected child actors.
Support for creating injected child actors.
Attributes
- Supertypes
-
class Objecttrait Matchableclass 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 Objecttrait Matchableclass Any
- Known subtypes
-
object Futures.type
Provider for the default flow materializer
Provider for the default flow materializer
Attributes
- Supertypes
Helper to access the application defined Pekko Actor system.
Helper to access the application defined Pekko Actor system.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Pekko.type
Components for configuring Pekko.
Components for configuring Pekko.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
Provider for an Pekko Typed Scheduler.
Pekko Typed components.
Pekko Typed components.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes