QnaList > Groups > Akka-User > Mar 2016
faq

[akka-user] Futures, Ask, And Receive Invocations. How Are They Handled In Akka?

Hi there,
We are developing a tool to aid Akka's developers reason about programs.
We will be very grateful if someone could help us educate our self about 
how "Futures" and "Ask" pattern is handled in Akka.
So our questions are as follow:
- If an ask statement, that sends a message *m1* from *a1* to *a2* 
(actors), must *a2* reply right away in the same "receive" invocation? or 
we can have another *receive* invocation reply to that ask? (I mean by 
reply also resolving the future)
- How can that be implemented (abstractly speaking) since *a2* doesn't have 
an explicit handle for the Future object returned by the above ask?
    - Is there a "mapping" between which message sent back to *a1* resolves 
which Future it asked for? If so, how to map that? (do you encapsulate the 
original message *m1* inside the later message sent from a1 to a2 for 
replying, and then the ActorSystem knows how to resolve that Future in the 
destination actor?)
We need to know about this since our model is to be kept more generic than 
how Akka does that but the front-end that is to parse Akka needs to do 
these specifics and puts them in terms of our model.
Thanks a lot in advance and all appreciation!
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

asked Mar 24 2016 at 12:25

Mohammed Al-Mahfoudh 's gravatar image



4 Replies for : [akka-user] Futures, Ask, And Receive Invocations. How Are They Handled In Akka?
The sender for the message will be linked back to the specific Future. As
long as the original sender is used to reply, the expected Future will be
completed.
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

answered Mar 25 2016 at 02:15

Derek Williams 's gravatar image


Hi Derek, 
Thanks a lot for the reply!
I am not sure I get what you are saying exactly, I am trying to understand:
As long as the original sender is used to reply, a1 is the sender, so if we 
are replying back to a1 from say a2 (the original receiver) but from 
another invocation of a2 "receive" method by say a3 (if possible by 
Akka),,, will it be linked back to a1? (how if so, the mapping is what is 
puzzling me if it is at all possible for above scenario, how is it done in 
the ActorSystem?)
Thanks and best,
Mo
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

answered Mar 25 2016 at 12:57

Mohammed Al-Mahfoudh 's gravatar image


no, a2 does not need to reply immediately in the same receive 
invocation.  yes, another iteration of the receive loop can reply. 
another actor even can reply to the future.
when you call ask(), what happens under the covers is a temporary actor 
is created as a mediator between a1 and a2.  this temporary actor (call 
it temp1) holds the future.  when the message is sent from a1 to a2, 
ask() actually sends the message to temp1, which then resends the 
message.  this is important, because it changes the sender address to 
that of temp1, not a1.  when a2 receives the message, sender() =temp1.  when a2 replies, temp1 receives the message and completes the 
future.
no, there is no mapping.  you have to do so yourself (if that is 
important to you) by mapping the future returned  from ask().
-Michael
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

answered Mar 25 2016 at 14:09

Michael Frank 's gravatar image


Michael, thank you so much! this answers all my questions.
Fantastic and clean how these are done under the hood. I will make sure to 
stick closely to the mediating temp holding the future then resolving it. 
Kudos,
Mo
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

answered Mar 25 2016 at 14:59

Mohammed Al-Mahfoudh 's gravatar image


Related discussions

Tagged

Group Akka-user

asked Mar 24 2016 at 12:25

active Mar 25 2016 at 14:59

posts:5

users:3

Akka-dev

Akka-user

©2013 QnaList.com . QnaList is part of ZisaTechnologies LLC.