Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var tickCancellable: Option[Cancellable] = None
override def receiveCommand = {
// ...
case TickCountdown => game match {
case rg: RunningGame => handleChanges(rg.tickCountdown())
case _ =>
log.warning("Game is not running, cannot update countdown")
cancelCountdownTick()
}
}
def scheduleCountdownTick() = {
val cancellable =
system.scheduler.schedule(1.second, 1.seconds, self, TickCountdown)
tickCancellable = Some(cancellable)
}
def cancelCountdownTick() = {
tickCancellable.foreach(_.cancel())
tickCancellable = None
}
override def receiveRecover = {
// ...
case RecoveryCompleted =>
if (game.isRunning)
scheduleCountdownTick()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment