Class: Fibre::Rack::FiberPool

Inherits:
Object
  • Object
show all
Defined in:
lib/fibre/rack/fiber_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) {|Fibre.pool| ... } ⇒ FiberPool

Returns a new instance of FiberPool.

Yields:



4
5
6
7
8
# File 'lib/fibre/rack/fiber_pool.rb', line 4

def initialize(app, options={})
  @app = app
  yield Fibre.pool if block_given?
  @rescue_exception = options[:rescue_exception] || (->(env, ex) { [500, {}, ["Internal Server Error"]] })
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fibre/rack/fiber_pool.rb', line 10

def call(env)
  call_app = lambda do
    result = @app.call(env)
    env['async.callback'].call result
  end

  Fibre.pool.checkout(&call_app)
  throw :async
rescue => ex
  @rescue_exception[env, ex]
end