Hello Andy!

Indeed, you'll want to avoid blocking in an actor's receive method - so if
you have blocking io stuff, you should definitely push it out into a
Future, to unblock the Actor.

If you block in an Actor’s receive, it won’t be able to process any other
message until it’s done with this blocking stuff.

Futures still need some execution context (basically like a thread pool),
in order for “someone” to execute them.
While you can use the same context as the actor (import context.dispatcher)
I’d rather suggest configuring a dedicated dispatcher for
“my-specific-blocking-stuff”,
and then use it when you spin off this blocking operation.

Configuring and using dispatchers (which are execution contexts) is
explained here:
java: <http://doc.akka.io/docs/akka/snapshot/java/dispatchers.html>
http://doc.akka.io/docs/akka/snapshot/java/dispatchers.html / scala:
<http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html>
http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html

So an example could look like this:

class Act extends Actor {
  *implicit* val blockingStuffContext =
system.dispatchers.lookup(“blocking-stuff-dispatcher”)

  def receive = {
    case x =>
      Future {
        // blocking stuff with x, will use blockingStuffContext as
execution context
      }
  }
}

You should tweak that dispatcher to suit your needs;
The cool thing is that you can group the workload by using specific
dispatchers for specific types of work and then tweak them separately.

I hope this helps!
-- 
Konrad Malawski

On Saturday, 8 March 2014 at 18:36, Andy C wrote:

Hi,

Most my stuff is reactive and async and Actors seems to be perfect to fit
the bill with an exception of a certain legacy I/O. It has to be handled
within Actor itself and it might take from seconds to even an hour to
complete.

So what is the best way to handle that within an Actor, can I just start
that I/O and let it run within an actor? What is going to happen to
messages coming  to that actor? Can I create a Future/Promise inside which
just will send an completion event to itself?

In another words, what is idiomatic way of handling blocking I/O within
Actors.

Please advise,
Andy

-- 
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups
"Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to