Skip to content

Commit

Permalink
not sure what all these delays were about
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Mar 23, 2016
1 parent 249ebbf commit 402e1e2
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions modules/round/src/main/Titivate.scala
Expand Up @@ -25,10 +25,6 @@ private[round] final class Titivate(

def scheduler = context.system.scheduler

val delayDuration = 200 millis
def delayF(f: => Funit): Funit = akka.pattern.after(delayDuration, scheduler)(f)
def delay(f: => Unit): Funit = akka.pattern.after(delayDuration, scheduler)(Future(f))

def scheduleNext = scheduler.scheduleOnce(10 seconds, self, Run)

def receive = {
Expand All @@ -40,32 +36,36 @@ private[round] final class Titivate(

case Run =>
$enumerate.over[Game]($query(Query.checkable), 5000) { game =>
if (game.finished || game.isPgnImport) delayF {

if (game.finished || game.isPgnImport)
GameRepo unsetCheckAt game
}
else if (game.outoftime(_ => chess.Clock.maxGraceMillis)) delay {

else if (game.outoftime(_ => chess.Clock.maxGraceMillis)) fuccess {
roundMap ! Tell(game.id, Outoftime)
}
else if (game.abandoned) delay {

else if (game.abandoned) fuccess {
roundMap ! Tell(game.id, Abandon)
}
else if (game.unplayed) delayF {

else if (game.unplayed) {
bookmark ! lila.hub.actorApi.bookmark.Remove(game.id)
GameRepo remove game.id
}

else game.clock match {
case Some(clock) if clock.isRunning => delayF {

case Some(clock) if clock.isRunning =>
val minutes = (clock.estimateTotalTime / 60).toInt
GameRepo.setCheckAt(game, DateTime.now plusMinutes minutes)
}
case Some(clock) => delayF {

case Some(clock) =>
val hours = Game.unplayedHours
GameRepo.setCheckAt(game, DateTime.now plusHours hours)
}
case None => delayF {

case None =>
val days = game.daysPerTurn | game.hasAi.fold(Game.aiAbandonedDays, Game.abandonedDays)
GameRepo.setCheckAt(game, DateTime.now plusDays days)
}
}
} andThenAnyway scheduleNext
}
Expand Down

0 comments on commit 402e1e2

Please sign in to comment.