scala - What happens in Future.pipeTo within actor -
i have call 3rd party library(which returs future) within actor receive. piping future self, can process reply messsage in 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
what overhead of approach?
will there separate thread allocated each such pipeto statement?
- if so, should there thread pool manage pipeto avoid threads getting used up?
thank you
what victor says, essentially: overhead of pipeto
low: creates 1 closure, sends 1 message. that's it, no additional threading involved. message being sent thread on future
has been completed, , received, actor messages, on dispatcher has been configured given actor.
you should take care of executioncontext
calltothirdpartylib
though. if uses blocking calls inside, , use default akka dispatcher run (what code suggests), might run out of threads quickly. however, seems off-topic question.
wiki
Comments
Post a Comment