Class: Rhoconnect::Middleware::Async
- Inherits:
-
Object
- Object
- Rhoconnect::Middleware::Async
- Defined in:
- lib/rhoconnect/async.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) {|_self| ... } ⇒ Async
constructor
A new instance of Async.
Constructor Details
Instance Method Details
#call(env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rhoconnect/async.rb', line 39 def call(env) f = Fiber.current # making a copy is crucial here # otherwise 'env' will not be the same # in the deferred execution aenv = env.dup operation = proc { res = nil aenv['REQUEST_THREAD'] = Thread.current if(aenv['RHO_ABORT_PROCESS']) res = [500, 'Request is aborted'] else res = @app.call(aenv) end res } result = nil callback = proc { |proc_res| result = proc_res; f.resume } EventMachine.defer operation, callback Fiber.yield result end |