rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 8e5d4ef9cb64dea9a299ed810a35a30d07fb2110 444 bytes (raw)
$ git show v2.0.0:lib/rainbows/rev/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
24
 
# -*- encoding: binary -*-
# :enddoc:
require 'rainbows/rev'

class Rainbows::Rev::Master < Rev::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