From 6d46978bdc8d2ee4263431ecdcada53389b12597 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 22 Oct 2010 02:51:18 +0000 Subject: fiber_{pool,spawn}: unindent Reduces confusion for constant resolution/scoping rules and lowers LoC. --- lib/rainbows/fiber_spawn.rb | 47 ++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'lib/rainbows/fiber_spawn.rb') diff --git a/lib/rainbows/fiber_spawn.rb b/lib/rainbows/fiber_spawn.rb index 1a0da04..17bd884 100644 --- a/lib/rainbows/fiber_spawn.rb +++ b/lib/rainbows/fiber_spawn.rb @@ -1,33 +1,28 @@ # -*- encoding: binary -*- require 'rainbows/fiber' -module Rainbows +# Simple Fiber-based concurrency model for 1.9. This spawns a new +# Fiber for every incoming client connection and the root Fiber for +# scheduling and connection acceptance. This exports a streaming +# "rack.input" with lightweight concurrency. Applications are +# strongly advised to wrap all slow IO objects (sockets, pipes) using +# the Rainbows::Fiber::IO class whenever possible. +module Rainbows::FiberSpawn + include Rainbows::Fiber::Base - # Simple Fiber-based concurrency model for 1.9. This spawns a new - # Fiber for every incoming client connection and the root Fiber for - # scheduling and connection acceptance. This exports a streaming - # "rack.input" with lightweight concurrency. Applications are - # strongly advised to wrap all slow IO objects (sockets, pipes) using - # the Rainbows::Fiber::IO class whenever possible. - - module FiberSpawn - include Fiber::Base - - def worker_loop(worker) # :nodoc: - init_worker_process(worker) - Fiber::Base.setup(self.class, app) - limit = worker_connections - - begin - schedule do |l| - break if G.cur >= limit - io = l.kgio_tryaccept or next - ::Fiber.new { process(io) }.resume - end - rescue => e - Error.listen_loop(e) - end while G.alive || G.cur > 0 - end + def worker_loop(worker) # :nodoc: + init_worker_process(worker) + Rainbows::Fiber::Base.setup(self.class, app) + limit = worker_connections + begin + schedule do |l| + break if G.cur >= limit + io = l.kgio_tryaccept or next + Fiber.new { process(io) }.resume + end + rescue => e + Rainbows::Error.listen_loop(e) + end while G.alive || G.cur > 0 end end -- cgit v1.2.3-24-ge0c7