in pekko-sample-persistence-dc-scala/src/main/scala/sample/persistence/res/bank/BankAccount.scala [61:74]
private def commandHandler(state: State, command: Command): Effect[Event, State] = command match {
case Deposit(amount, ack) =>
Effect.persist(Deposited(amount)).thenRun(_ => ack ! StatusReply.ack())
case Withdraw(amount, ack) =>
if (state.balance - amount >= 0) {
Effect.persist(Withdrawn(amount)).thenRun(_ => ack ! StatusReply.ack())
} else {
Effect.none.thenRun(_ => ack ! StatusReply.error("insufficient funds"))
}
case GetBalance(replyTo) =>
Effect.none.thenRun(_ => replyTo ! state.balance)
case AlertOverdrawn(amount) =>
Effect.persist(Overdrawn(amount))
}