Skip to content

Instantly share code, notes, and snippets.

@pjazdzewski1990
Created May 15, 2015 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjazdzewski1990/9f6566284a483150afb0 to your computer and use it in GitHub Desktop.
Save pjazdzewski1990/9f6566284a483150afb0 to your computer and use it in GitHub Desktop.
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