Akka: What happens when you tell an ActorRef and i

2019-05-25 03:06发布

问题:

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.