CanAsk
This class is used to establish a connection between a message class and the related response class using the ASK pattern. ask() requires a given instance of CanAsk. This ensures at COMPILE TIME that if ask() is called with a message of M
, an instance of R
(or a failed/cancelled IO
) is guaranteed to be returned.
{{ sealed trait Message
case class MyMessage() extends Message case class MyOtherMessage() extends Message case class MyResponse()
given CanAsk[MyMessage, MyResponse] = canAsk
...
for myActor <- ... // spawn an Actor[Command] myResponse <- myActor ? MyMessage() // this will compile, as there is a given instance of // CanAsk[MyMessage, MyResponse]. The Compiler will also know // that myResponse os of type MyResponse, not generic type Response. myResponse <- myActor ? MyOtherMessage() // this will NOT compile, as there is no given instance of // CanAsk[MyOtherMessage, ?]. _ <- myActor ! MyOtherMessage() // this will compile, as TELL does not require any givens yield () }}
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any