Class: Rack::FiberPool
- Inherits:
-
Object
- Object
- Rack::FiberPool
- Defined in:
- lib/rack/fiber_pool.rb
Constant Summary collapse
- VERSION =
'0.9.3'
- SIZE =
100
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) {|@fiber_pool| ... } ⇒ FiberPool
constructor
The size of the pool is configurable:.
Constructor Details
#initialize(app, options = {}) {|@fiber_pool| ... } ⇒ FiberPool
11 12 13 14 15 16 |
# File 'lib/rack/fiber_pool.rb', line 11 def initialize(app, ={}) @app = app @fiber_pool = ::FiberPool.new([:size] || SIZE) @rescue_exception = [:rescue_exception] || Proc.new { |env, e| [500, {}, ["#{e.class.name}: #{e..to_s}"]] } yield @fiber_pool if block_given? end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/fiber_pool.rb', line 18 def call(env) call_app = lambda do env['async.orig_callback'] = env.delete('async.callback') begin result = @app.call(env) env['async.orig_callback'].call result rescue ::Exception => e env['async.orig_callback'].call @rescue_exception.call(env, e) end end @fiber_pool.spawn(&call_app) throw :async end |