1 # -*- encoding: binary -*-
2 require 'rainbows/fiber'
4 # Simple Fiber-based concurrency model for 1.9. This spawns a new
5 # Fiber for every incoming client connection and the root Fiber for
6 # scheduling and connection acceptance. This exports a streaming
7 # "rack.input" with lightweight concurrency. Applications are
8 # strongly advised to wrap all slow IO objects (sockets, pipes) using
9 # the Rainbows::Fiber::IO class whenever possible.
10 module Rainbows::FiberSpawn
11 include Rainbows::Fiber::Base
13 def worker_loop(worker) # :nodoc:
14 init_worker_process(worker)
15 Rainbows::Fiber::Base.setup(self.class, app)
16 limit = worker_connections
20 break if Rainbows.cur >= limit
21 io = l.kgio_tryaccept or next
22 Fiber.new { process(io) }.resume
25 Rainbows::Error.listen_loop(e)
26 end while Rainbows.alive || Rainbows.cur > 0