开发者

Can an Akka anonymous actor access self?

开发者 https://www.devze.com 2023-01-20 01:24 出处:网络
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):

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))
        }开发者_StackOverflow catch {
            case e => self.senderFuture.foreach(_.completeWithException(e))
        }
    }
    case _ =>
}


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") }
})
0

精彩评论

暂无评论...
验证码 换一张
取 消