爱国者
爱国者

Reputation: 4348

Actor not response

Take a look at the code snippet:

import scala.actors.Actor._

object ActorTest1 extends Application {
  val caller = self

  val badActor = actor {
     receive {
        case msg =>
          println(Thread.currentThread()+ " "+msg)
          caller ! "bbbb"
     }
  }

  badActor ! "aaaa"
  receive {
     case a: String => println(Thread.currentThread() + " " + a)
  }

}

After badActor resonse "bbbb" to the sender, the whole application block . but if I change caller ! "bbbb" to sender ! "bbbb", it will work.

Could anyone explain why ?

Upvotes: 1

Views: 92

Answers (1)

Alfredo Serafini
Alfredo Serafini

Reputation: 194

i think that your caller reference is actually a reference to self, which is not an actor instance! :-)

instead sender is a a valid instance, as you can see here: http://doc.akka.io/docs/akka/snapshot/scala/actors.html

Upvotes: 2

Related Questions