avoid wrapping messages when ask returns single type
This commit is contained in:
parent
859589b9d4
commit
9b0c3a486f
5 changed files with 106 additions and 44 deletions
|
|
@ -57,10 +57,12 @@ class ChannelDocSpec extends AkkaSpec {
|
|||
|
||||
import ChannelDocSpec._
|
||||
|
||||
class MsgA
|
||||
class MsgB
|
||||
class MsgC
|
||||
class MsgD
|
||||
trait Msg
|
||||
|
||||
class MsgA extends Msg
|
||||
class MsgB extends Msg
|
||||
class MsgC extends Msg
|
||||
class MsgD extends Msg
|
||||
|
||||
"demonstrate why Typed Channels" in {
|
||||
def someActor = testActor
|
||||
|
|
@ -115,6 +117,7 @@ class ChannelDocSpec extends AkkaSpec {
|
|||
implicit val timeout: Timeout = ??? // for the ask operations
|
||||
|
||||
val channelA: ChannelRef[(MsgA, MsgB) :+: TNil] = ???
|
||||
val channelA2: ChannelRef[(MsgA, MsgB) :+: (MsgA, MsgC) :+: TNil] = ???
|
||||
val channelB: ChannelRef[(MsgB, MsgC) :+: TNil] = ???
|
||||
val channelC: ChannelRef[(MsgC, MsgD) :+: TNil] = ???
|
||||
|
||||
|
|
@ -127,12 +130,15 @@ class ChannelDocSpec extends AkkaSpec {
|
|||
channelA <-!- fA // eventually send the future’s value to channelA
|
||||
fA -!-> channelA // same thing as above
|
||||
|
||||
// ask the actor; return type given in full for illustration
|
||||
val fB: Future[WrappedMessage[(MsgB, Nothing) :+: TNil, MsgB]] = channelA <-?- a
|
||||
val fBunwrapped: Future[MsgB] = fB.lub
|
||||
|
||||
val fB: Future[MsgB] = channelA <-?- a // ask the actor
|
||||
a -?-> channelA // same thing as above
|
||||
|
||||
// ask the actor with multiple reply types
|
||||
// return type given in full for illustration
|
||||
val fM: Future[WrappedMessage[ //
|
||||
(MsgB, Nothing) :+: (MsgC, Nothing) :+: TNil, Msg]] = channelA2 <-?- a
|
||||
val fMunwrapped: Future[Msg] = fM.lub
|
||||
|
||||
channelA <-?- fA // eventually ask the actor, return the future
|
||||
fA -?-> channelA // same thing as above
|
||||
|
||||
|
|
|
|||
|
|
@ -169,10 +169,10 @@ Operations on typed channels are composable and obey a few simple rules:
|
|||
* the operators are fully symmetric, i.e. ``-!->`` and ``<-!-`` do the same
|
||||
thing provided the arguments also switch places
|
||||
|
||||
* sending with ``-?->`` or ``<-?-`` always returns a
|
||||
``Future[WrappedMessage[_, _]]`` representing all possible reply channels,
|
||||
even if there is only one (use ``.lub`` to get a :class:`Future[_]` with the
|
||||
most precise single type for the value)
|
||||
* sending with ``-?->`` or ``<-?-`` returns a ``Future[WrappedMessage[_, _]]``
|
||||
representing all possible reply channels if there is more than one (use
|
||||
``.lub`` to get a :class:`Future[_]` with the most precise single type for
|
||||
the value)
|
||||
|
||||
* sending a :class:`Future[_]` with ``-!->`` or ``<-!-`` returns a new
|
||||
:class:`Future[_]` which will be completed with the value after it has been
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue