Sha256: f1834c1c3b90cfced974d77dbf8175995a4fc6ed50876d70089a1f70868cba9b

Contents?: true

Size: 985 Bytes

Versions: 11

Compression:

Stored size: 985 Bytes

Contents

# -*- 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 FiberSpawn
    include Fiber::Base

    def worker_loop(worker)
      init_worker_process(worker)
      Fiber::Base.const_set(:APP, app)
      limit = worker_connections
      fio = Rainbows::Fiber::IO

      begin
        schedule do |l|
          break if G.cur >= limit
          io = Rainbows.accept(l) or next
          ::Fiber.new { process_client(fio.new(io, ::Fiber.current)) }.resume
        end
      rescue => e
        Error.listen_loop(e)
      end while G.alive || G.cur > 0
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rainbows-0.94.0 lib/rainbows/fiber_spawn.rb
rainbows-0.93.0 lib/rainbows/fiber_spawn.rb
rainbows-0.92.0 lib/rainbows/fiber_spawn.rb
rainbows-0.91.1 lib/rainbows/fiber_spawn.rb
rainbows-0.91.0 lib/rainbows/fiber_spawn.rb
rainbows-0.90.2 lib/rainbows/fiber_spawn.rb
rainbows-0.90.1 lib/rainbows/fiber_spawn.rb
rainbows-0.90.0 lib/rainbows/fiber_spawn.rb
rainbows-0.9.0 lib/rainbows/fiber_spawn.rb
rainbows-0.8.0 lib/rainbows/fiber_spawn.rb
rainbows-0.7.0 lib/rainbows/fiber_spawn.rb