I don't follow your snippet. Receive is a partial function from Any to
Unit, so it doesn't return anything.

def receive = {
case Start => {
val futureResult = someFuture
someFuture pipeTo sender
}
}

You don't need to add an ask- you can just pipe someFuture to self or the
sender. The result will be queued in the sender's mailbox when the future
completes.
If you're careful about "closing over self" you can also implement
future.onComplete within the receive block.

If the sender is sensitive to the order of messages received, it can use
become() to change states or use the FSM trait.
http://letitcrash.com/post/54507231889/2-2-spotlight-simpler-use-of-stash

Hope this helps.


On Mon, Oct 13, 2014 at 6:47 AM, Joheinz <[email protected]> wrote:

> Hi *,
>
> Let's say I have an actor which receives a message Start and is processing
> this message asynchrounously.
>
> someActor ! start
>
> class SomeActor {
>   def receive = {
>     case Start =>
>       for {
>        _ <- someFuture
>       } yield ()
>   }
>
> Because processing of Start happens asynchronous it could be that
> SomeActor receives more messages before the processing of start is
> completed.
>
> What would be my options to improve this behaviour?
> - I could use Await.result - which does not seem to be a reasonable option
> - I could use the ask pattern and pipe the response back to the sender. In
> that case what would happen if other actors send me messages?
>
> Are there any other ways to deal with this situation? I am concerned that
> messages arrive when the actor is not in a stable state yet, and I would
> like to prevent this.
>
> Thanks,
> Markus
>
>
>
>
>
>  --
> >>>>>>>>>> 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.
>

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