tags:

views:

113

answers:

1

Can an Akka anonymous actor have access to self? In my particular case I'm wondering if I can reply back to the sender with code similar to this (does not compile due to self not being found):

val xmlLoader = Actor.init {
    println("xml loader started")
} receive {
    case LoadResource(url) => {
        try {
            val xml = XML.load( URL("content.xml") )
            self.senderFuture.foreach(_.completeWithResult(xml))
        } catch {
            case e => self.senderFuture.foreach(_.completeWithException(e))
        }
    }
    case _ =>
}
+3  A: 

Hi Brian,

first of all, thanks for using Akka, hope you're enjoying it!

I'd recommend:

actorOf(
new Actor {
 def receive = { case "foo" => self.reply_?("bar") }
})
Viktor Klang
Thanks Viktor, I was suspecting that the anonymity of the actor was the problem. Thanks for the clarification. And yes, I'm liking Akka a lot ;)
Brian Heylin
Cool, have fun and happy hAkking!
Viktor Klang