1 # -*- encoding: binary -*-
2 require 'rainbows/fiber'
4 # Simple Fiber-based concurrency model for 1.9. This spawns a new Fiber
5 # for every incoming client connection and the root Fiber for scheduling
6 # and connection acceptance.
8 # This concurrency model is difficult to use with existing applications,
9 # lacks third-party support, and is thus NOT recommended.
11 # This exports a streaming "rack.input" with lightweight concurrency.
12 # Applications are strongly advised to wrap all slow IO objects
13 # (sockets, pipes) using the Rainbows::Fiber::IO class whenever
15 module Rainbows::FiberSpawn
16 include Rainbows::Fiber::Base
18 def worker_loop(worker) # :nodoc:
19 init_worker_process(worker)
20 Rainbows::Fiber::Base.setup(self.class, app)
21 limit = worker_connections
25 break if Rainbows.cur >= limit
26 io = l.kgio_tryaccept or next
27 Fiber.new { process(io) }.resume
30 Rainbows::Error.listen_loop(e)
31 end while Rainbows.cur_alive