Class: Emmy::Rack::Async

Inherits:
Object
  • Object
show all
Defined in:
lib/emmy/rack/async.rb

Instance Method Summary collapse

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, options={})
  @app = app
  @rescue_exception = options[: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