rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob b253e67309394741b1473bb0b2f376e74db56bfa 481 bytes (raw)
$ git show em-deferred: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
24
 
# -*- encoding: binary -*-
# :enddoc:
require 'thread'
class Rainbows::Coolio::Master < Coolio::IOWatcher

  def initialize(queue)
    @reader, @writer = Kgio::Pipe.new
    super(@reader)
    @queue = queue
    @wbuf, @rbuf = "\0", "\0"
  end

  def <<(output)
    @queue << output
    @writer.kgio_trywrite(@wbuf)
  end

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

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