Don't use ask() -- you're blocking for no reason. Just tell() the other two 
actors, and finish what you can with the information you have. Then, when 
the responses from those two actors come in, do what you can with that 
information.

Jonas and Viktor wrote an article for O'Reilly where they said this:

Reactive programming... is a subset of asynchronous programming and a 
> paradigm where *the availability of new information drives the logic 
> forward rather than having control flow driven by a thread-of-execution*.


Emphasis is mine. Rather than depending on ask() to try to force everything 
into a single thread, accept that the information will come in sometime 
after you ask for it -- maybe not in the order you asked for it -- and 
finish the task after the answers come in.

On Friday, February 9, 2018 at 2:21:52 AM UTC-5, Tanmoy Bandyopadhyay wrote:
>
> Hello,
>
> I am new to Akka. I am a bit confused with parallel Akka calls from an 
> Akka actor. What I was trying to do is to make parallel-concurrent calls to 
> two other actors using ask and awaiting for future to get resolved.
>
> public class Actor1 extends UntypedActor {
>
> public void onReceive(Object message) throws Throwable {
> Future<Object> searchFuture1 = ask(actor2, requestMessage, 
> FUTURE_ACTOR_TIMEOUT);
> ResponseMessage responseMessage1 = (ResponseMessage) 
> Await.result(searchFuture1, Duration.create(FUTURE_ACTOR_TIMEOUT, 
> TimeUnit.MILLISECONDS));
>
> Future<Object> searchFuture2 = ask(actor3, requestMessage, 
> FUTURE_ACTOR_TIMEOUT);
> ResponseMessage responseMessage2 = (ResponseMessage) 
> Await.result(searchFuture2, Duration.create(FUTURE_ACTOR_TIMEOUT, 
> TimeUnit.MILLISECONDS));
>
> //logic to merge both the response messages
> }
> }
>
> It looks sequential while making the calls to the separate actors. I want 
> the calls(ask) to the actors in parallel. How can I achieve it.?Please help 
> me to understand.
>
> Thanks in Advance.
> Tanmoy
>
>

-- 
>>>>>>>>>>      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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to