summary refs log tree commit homepage
path: root/lib/rainbows/fiber/coolio/heartbeat.rb
blob: 7014dbe5cfa204c8bd058c76c658a6dbed40c392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
# -*- encoding: binary -*-
# :enddoc:
class Rainbows::Fiber::Coolio::Heartbeat < Coolio::TimerWatcher
  # ZZ gets populated by read_expire in rainbows/fiber/io/methods
  ZZ = Rainbows::Fiber::ZZ
  def on_timer
    exit if (! Rainbows.tick && Rainbows.cur <= 0)
    now = Rainbows.now
    fibs = []
    ZZ.delete_if { |fib, time| now >= time ? fibs << fib : ! fib.alive? }
    fibs.each { |fib| fib.resume if fib.alive? }
  end
end