0
def persist[A](event: A)(handler: (A) ⇒ Unit): Unit

def persistAll[A](events: Seq[A])(handler: (A) ⇒ Unit): Unit

For above method, is param passed to handler guaranted to be exactly the same(with same identifyHashCode) instance as the persisted event ?

According to my few tests, they are actually same, but I don't know akka will always ensure this even in the future release

Maroun
  • 94,125
  • 30
  • 188
  • 241
jilen
  • 5,633
  • 3
  • 35
  • 84

1 Answers1

1

From the source code, we can see they are exactly the same.

def persist[A](event: A)(handler: A => Unit): Unit = {
  if (recoveryRunning) throw new IllegalStateException("Cannot persist during replay. Events can be persisted when receiving RecoveryCompleted or later.")
  pendingStashingPersistInvocations += 1
  pendingInvocations addLast StashingHandlerInvocation(event, handler.asInstanceOf[Any => Unit])
  eventBatch ::= AtomicWrite(PersistentRepr(event, persistenceId = persistenceId,
    sequenceNr = nextSequenceNr(), writerUuid = writerUuid, sender = sender()))
}

You can see the same event be passed to AtomicWrite for persist & also passed to StashingHandlerInvocation for handle. I didn't see any reason for akka team to change this later. But no one can promise for future release even the maintainer I think, maybe you need to wait the man from lightbend. FYI.

atline
  • 28,355
  • 16
  • 77
  • 113
  • 1
    This official maillist may help you: [here](https://groups.google.com/forum/#!forum/akka-user) – atline Feb 11 '18 at 07:00