Reply without persisting events

How about a scenario where your update employee API is suppose to always return an updated Employee object but you may not wish to persist any events if there are no changes to update!

if(foundAnyChangesToUpdate)
  ctx.thenPersist(EmployeeUpdated)(_ => ctx.reply(Employee))
else
  ctx.thenPersistAll(Nil: _*)(() => ctx.reply(Employee))

I tried the code above in the else statement to persist 0 events and reply the employee object retrieved from the state as is. But this doesn’t seem to work! Is there any way to reply without persisting any events in Lagom? Or is it a wrong approach all together? Kindly suggest.

TIA.

Hi @codingkapoor,

In case you do not have events to persist you just do this:

ctx.reply(Employee)
ctx.done

Hope this helps.

Br,
Alan

2 Likes