Skip to content

Instantly share code, notes, and snippets.

@LukasGasior1
Last active August 29, 2015 14:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save LukasGasior1/253cd74fcdb53770460b to your computer and use it in GitHub Desktop.
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