rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 4877e8e96e7047483451e2bf30ef1d45fcd9c776 443 bytes (raw)
$ git show v2.1.0:lib/rainbows/coolio/master.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
 
# -*- encoding: binary -*-
# :enddoc:
require 'thread'
class Rainbows::Coolio::Master < Coolio::IOWatcher

  def initialize(queue)
    @reader, @writer = Kgio::Pipe.new
    super(@reader)
    @queue = queue
  end

  def <<(output)
    @queue << output
    @writer.kgio_trywrite("\0")
  end

  def on_readable
    if String === @reader.kgio_tryread(1)
      client, response = @queue.pop
      client.response_write(response)
    end
  end
end

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