Yep, that's how it works! :-)

-- 
Cheers,
Konrad 'ktoso’ Malawski
Akka @ Typesafe

On 17 July 2015 at 21:11:19, ahjohannessen ([email protected]) wrote:

If that defer works as explained, then I can reduce my code to this:

...
val durables = events map { e ⇒
  DurableEvent(e, pid).causedBy(cm)
}

persist(durables)(applyEvent)
defer()(_ ⇒ done)

...

That's rather nice :)

On Friday, July 17, 2015 at 8:04:54 PM UTC+1, ahjohannessen wrote:
Andrew, I have also run into that and never paid much attention to defer, 
solved my problem in a rather clumsy way:

private def processEvents(events: Seq[DomainEvent], cm: CommandMessage)(done: ⇒ 
Unit): Unit = {

  val durables = events map { e ⇒
    DurableEvent(e, pid).causedBy(cm)
  }

  if(durables.isEmpty) done else {
    val lastId = durables.last.eventId
    persist(durables) { pe ⇒
      applyEvent(pe)
      if(pe.eventId == lastId) done
    }
  }
}

On Friday, July 17, 2015 at 4:09:04 PM UTC+1, Andrew Easter wrote:
Ah, thanks. I'd got confused and thought the defer behaviour was only relevant 
when using persistAsync. Need to read the manual properly next time, doh!

On Friday, 17 July 2015 16:00:43 UTC+1, Ryan Bair wrote:
Hi Andrew,

There is the defer method which handles this case rather nicely.

case Message =>
  val events = ...
  persist(events)
  defer() { _ => sender() ! Ack } // Not run until persist completes

On Friday, July 17, 2015 at 10:47:01 AM UTC-4, Andrew Easter wrote:
I've got a persistent actor that, on processing a command, generates multiple 
events. There is support for persisting multiple events in the API:

def persist[A](events: immutable.Seq[A])(handler: A => Unit): Unit

In my use case, after all the events have been persisted, I wish to send an 
command acknowledgement to the sender:

sender() ! Ack

However, because the event handler is invoked per event, I can't easily achieve 
invoking the sender acknowledgement only once all events have been handled.

Am I missing something obvious that would help serve my use case?
--
>>>>>>>>>> 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