rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob f48f7ef77aec4df0d893a25beb1527db6648b89f 432 bytes (raw)
$ git show v2.1.0:lib/rainbows/fiber/coolio/heartbeat.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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

git clone https://yhbt.net/rainbows.git