This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Futures React within Actor

No replies
Pavel Chlupáček
Joined: 2011-07-04,
User offline. Last seen 42 years 45 weeks ago.

Hi folks,

can anyone please guide me how exactly react works in respect to
futures and actors?

Lets assume following code

class ActorForwardingToFuture extends DaemonActor {

def act() {
loop {
react {
case Foward(toActor,thisMessage) =>{
println("yes we want to forward message")
(toActor !! thisMessage).inputChannel.reactWithin(1000) {
case reply => println("yes, we have got reply on future")
case TIMEOUT => prinln("no chance, timeout")
}
println("This will not get executed")
}
}
}
}
}

now I see that println("This will not get executed") will never get
executed (which originally surprised me, as I have beleived that the
react only within given actor would cause the after-react code to be
ignored, not the one after future).

This behavior drived me to following conclusions, and I just would
like to reconfirm if them are correct:

1. The reply to future IS SYNCHRONIZED on parent actor, and not on the
future only
2. Obviously actor and future are sharing same threadpool (fork join)
3. In between reply to future actor may proceed freely the actual
messages designated to them and future reply would not block actor
from doing so

Are these assumptions correct? I didnt found anything specific on
actor's futures in the docs, books etc, and this part of story sees to
be quite gray, so I would appreciate any light on how the intended
behavior of Actor//Future/react is

Thanks a lot.

P.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland