rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 3d8d85ee9fd51b1a69a63a2e2b65410b263fddde 464 bytes (raw)
$ git show HEAD:lib/rainbows/fiber/coolio/server.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
# -*- encoding: binary -*-
# :enddoc:
class Rainbows::Fiber::Coolio::Server < Coolio::IOWatcher
  def to_io
    @io
  end

  def initialize(io)
    @io = io
    super(self, :r)
  end

  def close
    detach if attached?
    @io.close
  end

  def on_readable
    return if Rainbows.cur >= MAX
    c = @io.kgio_tryaccept and Fiber.new { process(c) }.resume
  end

  def process(io)
    Rainbows.cur += 1
    io.process_loop
  ensure
    Rainbows.cur -= 1
  end
end

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