restore Rainbows::HttpResponse.write for Cramp
[rainbows.git] / lib / rainbows / rev_fiber_spawn.rb
blobe9ea1dbf7f39bb1c5982f7e721f7c12496aa3d08
1 # -*- encoding: binary -*-
2 require 'rainbows/fiber/rev'
4 module Rainbows
6   # A combination of the Rev and FiberSpawn models.  This allows Ruby
7   # 1.9 Fiber-based concurrency for application processing while
8   # exposing a synchronous execution model and using scalable network
9   # concurrency provided by Rev.  A "rack.input" is exposed as well
10   # being Sunshowers-compatible.  Applications are strongly advised to
11   # wrap all slow IO objects (sockets, pipes) using the
12   # Rainbows::Fiber::IO or a Rev-compatible class whenever possible.
13   module RevFiberSpawn
15     include Base
16     include Fiber::Rev
18     def worker_loop(worker)
19       Rainbows::Response.setup(Rainbows::Fiber::Rev::Server)
20       init_worker_process(worker)
21       Server.const_set(:MAX, @worker_connections)
22       Rainbows::Fiber::Base.setup(Rainbows::Fiber::Rev::Server, nil)
23       Server.const_set(:APP, G.server.app)
24       Heartbeat.new(1, true).attach(::Rev::Loop.default)
25       kato = Kato.new.attach(::Rev::Loop.default)
26       Rainbows::Fiber::IO.const_set(:KATO, kato)
27       LISTENERS.map! { |s| Server.new(s).attach(::Rev::Loop.default) }
28       ::Rev::Loop.default.run
29     end
30   end
31 end