Class: Emmy::Rack::Async
- Inherits:
-
Object
- Object
- Emmy::Rack::Async
- Defined in:
- lib/emmy/rack/async.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Async
constructor
A new instance of Async.
Constructor Details
#initialize(app, options = {}) ⇒ Async
Returns a new instance of Async.
4 5 6 7 |
# File 'lib/emmy/rack/async.rb', line 4 def initialize(app, ={}) @app = app @rescue_exception = [:rescue_exception] || (->(env, ex) { [500, {}, ["Internal Server Error"]] }) end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/emmy/rack/async.rb', line 9 def call(env) call_app = lambda do result = @app.call(env) env['async.callback'].call result end Emmy.async(&call_app) throw :async rescue => ex @rescue_exception[env, ex] end |