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

  1. what overhead of approach?

  2. will there separate thread allocated each such pipeto statement?

  3. 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

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -