The common way for pipes:

def receive = {
    case m =>
        val s = sender()
        f(m) pipeTo self
        context.become({
          case e:Status.Failure =>
             s ! e
             context.unbecome()
             unstashAll()
          case ok:OkType =>
             s ! ok
             internalState = mutate(internalState, ok)
             context.unbecome()
             unstashAll()
          case _ =>
             stash()
        })
}

With FSM I'm doing something more complex, introducing "Processing" data 
type with a Receive handler inside.

This cannot be performed using akka streams (at least I don't know how to 
do it). Problem is not in resolving future (with flatMap, mapAsync, 
pipeTo), but in preserving actor's state.

For command messages actor should stop processing until remote job is done.

I dislike this pattern due to verbosity and mistakes.

For better understanding: I have a persistent actor per aggregate, in a 
sharded environment. So I have to mutate aggregates internal data in a 
transactional manner -- receiving Commands, performing external action with 
future, saving event, mutating internal state.



On Thursday, May 14, 2015 at 9:19:30 PM UTC+3, Andrew Gaydenko wrote:
>
> On Thursday, May 14, 2015 at 8:46:27 PM UTC+3, Patrik Nordwall wrote:
>>
>> If there are no relationship (no ordering) between the future result and 
>> other incoming messages you can just use pipe, without stash.
>>
>
> Let's assume at the moment we have:
>
> def receive = {
>   case Msg(data) =>
>     def job = callReturningFuture(data)(context.dispatcher)
>     Await.result(job, 1000.millis)
> }
>
> What is the suggestion?
>
>

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