Akka: What happens when you tell an ActorRef and it expects you to ask?

烂漫一生 提交于 2019-12-07 19:26:37

问题


I have the following:

val future = myActor ? Message

And in my actor my receive message has something like this:

sender ! Response

If I do the following and ignore the response, is there any negative impact?

myActor ! Message

Maybe I'm just missing where it says this in the documentation. Is it like a method that returns a value and the caller doesn't assign the return value to anything? If I make that call from another actor is there going to be some weird threading issue or memory leaks that result from it? My unit tests don't seem to be affected but it's kind of a contrived. I'm hoping I'm just over-thinking the problem and maybe I can't find the answer because it's a stupid question that no one in their right mind asks.


回答1:


With ask pattern Response is received by temporary light-weight actor (PromiseActorRef).

In case of myActor ! Message there should be implicit ActorRef in scope. Response will be sent to this implicit ActorRef. This message will not be garbage-collected until you explicitly read it.

If there is no implicit ActorRef in scope Actor.noSender is used and Response will be forwarded to system's deadLetters.

If you make that call from another actor this Response will be delivered to message box of this another actor.



来源:https://stackoverflow.com/questions/18094145/akka-what-happens-when-you-tell-an-actorref-and-it-expects-you-to-ask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!