Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
case class IncRollsCount(rolledNumber: Int) extends Command
case class RollsCountIncreased(rolledNumber: Int) extends Event
case object GetState extends Command
class StatsActor extends PersistentActor {
override val persistenceId = "rolls_stats"
var state: Stats = Stats(Map.empty)
def applyEvent(event: Event) = event match {
case RollsCountIncreased(rolledNumber) =>
state = state.incRollsCount(rolledNumber)
}
override def receiveCommand = {
case IncRollsCount(rolledNumber) =>
persist(RollsCountIncreased(rolledNumber))(applyEvent)
case GetState =>
sender() ! state
}
override def receiveRecover = {
case ev: Event => applyEvent(ev)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment