Ensuring sleep value is at least zero.
authorSiraaj Khandkar <siraaj@khandkar.net>
Thu, 9 Aug 2012 18:26:39 +0000 (14:26 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Thu, 9 Aug 2012 18:26:39 +0000 (14:26 -0400)
003/src/life.erl

index f4b1fe5..605fa95 100644 (file)
@@ -74,12 +74,16 @@ life_loop(
     },
 
     NewTimeMil = NewTime / 1000,
-    NextGenDelay = round(?GEN_INTERVAL - NewTimeMil),
+    NextGenDelay = at_least_zero(round(?GEN_INTERVAL - NewTimeMil)),
     timer:sleep(NextGenDelay),
 
     life_loop(NewState).
 
 
+at_least_zero(Integer) when Integer >= 0 -> Integer;
+at_least_zero(_) -> 0.
+
+
 do_print_screen(Board, Bar, X, Y, N, GenCount, Time, PrintTime) ->
     ok = do_print_status(Bar, X, Y, N, GenCount, Time, PrintTime),
     ok = do_print_board(Board).
This page took 0.019874 seconds and 4 git commands to generate.