Don’t ever use callbacks in actors, you’ll shoot yourself in the foot sooner or 
later. Use `pipeTo` to send the result of the `Future` to `self` and handle it 
(and `Statue.Failure`) like any other message.

Heiko

--

Heiko Seeberger
Home: heikoseeberger.de <http://heikoseeberger.de/>
Twitter: @hseeberger <https://twitter.com/hseeberger>
Public key: keybase.io/hseeberger <https://keybase.io/hseeberger>
> On 21 Sep 2015, at 15:18, John Ulric <[email protected]> wrote:
> 
> Hi all, I create a Future in an actor's onReceive method, and use onComplete 
> to trigger a side-effect when that future completes, like this:
> 
> public void onReceive(Object message) throws Exception {
>     final ActorRef sender = sender();
>     Future f = ...;
>     f.onComplete(new OnComplete() {
>         @Override
>         public void onComplete(Throwable throwable, Object object) throws 
> Throwable {
>             // Can use final sender here.
>             // What actor methods are allowed here?
>         }
>     }, context().dispatcher());
> }
> 
> It's clear that one must not modify the actor's state from within the 
> onComplete callback, and it's clear that one must use the self() and sender() 
> methods outside the callback and pass it into the onComplete as finals. But 
> what other actor methods are allowed inside the onComplete method? Is it ok 
> to use context(), eg?
> 
> Thanks.
> 
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/>
> >>>>>>>>>> Check the FAQ: 
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html 
> >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html>
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user 
> >>>>>>>>>> <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 [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/akka-user 
> <http://groups.google.com/group/akka-user>.
> For more options, visit https://groups.google.com/d/optout 
> <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 [email protected].
To post to this group, send email to [email protected].
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