Reputation: 33
I am wondering which Tell method should be used by default?
The docs at
http://getakka.net/docs/working-with-actors/sending-messages
hint that Tell(message, sender) is the preferred way of sending a message, however looking at Akka.Net code, it seems that Tell(message) calls the two argument version anyway with the sender field filled automatically.
Apart from calling simpler code with two argument version of Tell (less ifs under the hood), is there another reason why it should be used instead of a single argument version (when calling from inside an actor)?
Upvotes: 1
Views: 251
Reputation: 4836
I lean towards calling things with least amount of dependancies necessary to achieve the task at hand.
Anyway aside from that. The article you are referring to is really saying favour Tell over Ask<>. I do not think the intent is to specify which overload is preferable to use. Often you will use the one with Sender because you want a response to goto a different actor.
Calling Tell(blah, Self)
seems horribly redundant which is probably why the overload exists. The times you need to be careful are when you are telling from a place where you do not have the reference to Self or a suitable Sender EG from tests.
Another common scenario is at a service layer, here (ie the surface of the system) you will often find Ask<> is appropriate if a response is synchronously required. The point of that article is to point out that reactive systems are often not wanting to be synchronous (ask based) and so you should have tell based pathways throughout (eg in a web context to a Rx hub maybe)
Upvotes: 1