about summary refs log tree commit homepage
path: root/lib/rainbows/fiber/coolio/heartbeat.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-28 17:59:27 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-28 18:00:04 -0800
commit40445641f11f01c6a24bf96c8b80eed5fd33a512 (patch)
tree57a7652cc03f46407d51babfd04d72d1c401ac99 /lib/rainbows/fiber/coolio/heartbeat.rb
parent3495d59763e6159975debf32728dc53fc41c5ea1 (diff)
downloadrainbows-40445641f11f01c6a24bf96c8b80eed5fd33a512.tar.gz
complete Rev => Coolio renaming
We use Cool.io internally everywhere now, but preserve
Rev-based models for anybody using them.
Diffstat (limited to 'lib/rainbows/fiber/coolio/heartbeat.rb')
-rw-r--r--lib/rainbows/fiber/coolio/heartbeat.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/rainbows/fiber/coolio/heartbeat.rb b/lib/rainbows/fiber/coolio/heartbeat.rb
new file mode 100644
index 0000000..f48f7ef
--- /dev/null
+++ b/lib/rainbows/fiber/coolio/heartbeat.rb
@@ -0,0 +1,15 @@
+# -*- encoding: binary -*-
+# :enddoc:
+class Rainbows::Fiber::Coolio::Heartbeat < Coolio::TimerWatcher
+  G = Rainbows::G
+
+  # ZZ gets populated by read_expire in rainbows/fiber/io/methods
+  ZZ = Rainbows::Fiber::ZZ
+  def on_timer
+    exit if (! G.tick && G.cur <= 0)
+    now = Time.now
+    fibs = []
+    ZZ.delete_if { |fib, time| now >= time ? fibs << fib : ! fib.alive? }
+    fibs.each { |fib| fib.resume if fib.alive? }
+  end
+end