On Mon, Feb 12, 2018 at 11:26 AM, Kilic Ali-Firat <kilic.alifi...@gmail.com>

> Hi Akka team,

I'm not the Akka team, but...

> case class Worker() extends Actor {
>   trait Message
>   case class M1(x : Int) extends Message
>   case class M2(x : Int) extends Message
>   trait Result
>   case  Sucess(m : Message) extends Result
>   case Failed(m : Message) extends Result
>   def processM1(m : M1) : Future[Result]
>   def processM2(m : M2) : Future[Result]
>   override def receive = {
>     case m : M1 => this.processM1(m) pipeTo sender()
>     case m : M2 => this.processM2(m) pipeTo sender()
>   }
> }
> Imagine that mailbox of a worker *has 4 messages : M1, M2, M3, M4.*
> It will process the mailbox messages per message starting by M1, then M2,
> then M3 and finally M4.
> My question about order processing is : Do an Actor wait the completion of
> current message before passing to the next one in the mailbox ?

Depends on your definitions.  Keep in mind that Akka is focused on
*synchronous* processing -- if the message processing is synchronous, then
yes, a given Actor will only process one at a time.

The problem is, you're spawning off separate threads with those Futures.
Akka has no insight or control over those, so it doesn't and can't wait for
them to be finished.  That's why you are seeing the behavior that you are.

> If I'm a wrong, Does Akka have a mechanism to wait for the completion of
> current message processing before passing to the next one ?

I don't know of any built-in way to do this.  The pattern I usually see
(and have sometimes used myself) is to:

* Mix the Stash trait in;
* When I start processing, become() a different state that stash()es all
messages except the Result;
* When processing finishes (once you've dealt with the Result),
unstashAll() and unbecome() back to the main state.

So basically, it isn't "waiting", it's storing all of the received messages
off to the side in the interim, and them putting them back into the mailbox
when you're ready to continue.  You get an effect similar to waiting, but
without blocking anything.

>>>>>>>>>>      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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to