Reputation: 551
I have a call to 3rd party library(which returs a future) within my actor receive. I am piping that future to Self, so that I can process the reply as a messsage in the mailbox.
class MyActor{
def receive:Receive = {
case x:Message => {
val future = callToThridPartyLib(x)
future pipeTo self
}
case x:Reply => {
//process reply received on future completion
}
}
}
My questions are
What is the overhead of this approach?
Will there be a separate thread allocated for each such pipeTo statement?
Thank you
Upvotes: 0
Views: 609
Reputation: 11308
What Victor says, but essentially:
The overhead of pipeTo
is very low: it creates one closure, which sends one message. That's it, no additional threading involved. The message is being sent from the thread on which the Future
has been completed, and will be received, like all the actor messages, on the dispatcher that has been configured for the given actor.
You should take care of ExecutionContext
for that callToThirdPartyLib
though. If it uses blocking calls inside, and you use default Akka dispatcher to run it (what your code suggests), you might run out of threads quickly. However, this seems to be off-topic for the question.
Upvotes: 4