Let's see what the experts say, but you could put the actor in a
"suspended" state using become(). Take a look at the link I provided and
see if that makes any sense.

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

> What I had been trying to express (non-native speaker), is that when the
> actor processes/creates a future in the receive method, it will very
> quickly proceed the next message, without a guarantee that the future is
> completed. What I somehow would like to achieve: avoid Await.result due to
> its blocking characteristics, but also prevent the actor from creating to
> much noise. I do not know it is possible, but I imagine that I could
> somehow tell the mailbox of the actor to proceed only when the future the
> actor had created is completed.
>
> Hopefully that makes more sense,
>
> Markus
>
>
> 2014-10-13 16:28 GMT+02:00 Richard Rodseth <[email protected]>:
>
>> 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.
>>
>
>  --
> >>>>>>>>>> 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