Merge: Generalize MEntity visibility
[nit.git] / lib / realtime.nit
index 6e312ef..243b5d8 100644 (file)
@@ -120,7 +120,22 @@ extern class Timespec `{struct timespec*`}
 end
 
 # Keeps track of real time
+#
+# ~~~
+# var clock = new Clock
+#
+# # sleeping at least 1s
+# 1.0.sleep
+# assert clock.total >= 1.0
+# assert clock.lapse >= 1.0
+#
+# # sleeping at least 5ms
+# 0.005.sleep
+# assert clock.total >= 1.005
+# assert clock.lapse >= 0.005
+# ~~~
 class Clock
+       super FinalizableOnce
 
        # TODO use less mallocs
 
@@ -181,4 +196,10 @@ class Clock
                dt.free
                return r
        end
+
+       redef fun finalize_once
+       do
+               time_at_beginning.free
+               time_at_last_lapse.free
+       end
 end