Don't sleep longer than necessary to meet the interval.
authorSiraaj Khandkar <siraaj@khandkar.net>
Thu, 9 Aug 2012 13:16:35 +0000 (09:16 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Thu, 9 Aug 2012 13:16:35 +0000 (09:16 -0400)
003/src/life.erl

index ddb5115..f4b1fe5 100644 (file)
@@ -7,7 +7,7 @@
 -define(CHAR_ALIVE, 111).  % "o"
 -define(CHAR_BAR,    45).  % "-"
 
--define(INTERVAL, 100).
+-define(GEN_INTERVAL, 100).
 
 
 -record(state, {x            :: non_neg_integer()
@@ -73,7 +73,10 @@ life_loop(
                           ,print_time   = PrintTime
     },
 
-    timer:sleep(?INTERVAL),
+    NewTimeMil = NewTime / 1000,
+    NextGenDelay = round(?GEN_INTERVAL - NewTimeMil),
+    timer:sleep(NextGenDelay),
+
     life_loop(NewState).
 
 
This page took 0.020642 seconds and 4 git commands to generate.