class EBuilder::ExtendedRack

Public Instance Methods

call(env) click to toggle source
# File lib/e-builder/base.rb, line 329
def call(env)
  result, callback = app.call(env), env['async.callback']
  return result unless callback and async?(*result)
  after_response { callback.call result }
  setup_close(env, *result)
  throw :async
end

Private Instance Methods

after_response(&block) click to toggle source
# File lib/e-builder/base.rb, line 344
def after_response(&block)
  raise NotImplementedError, "only supports EventMachine at the moment" unless defined? EventMachine
  EventMachine.next_tick(&block)
end
async?(status, headers, body) click to toggle source
# File lib/e-builder/base.rb, line 349
def async?(status, headers, body)
  return true if status == -1
  body.respond_to? :callback and body.respond_to? :errback
end
setup_close(env, status, header, body) click to toggle source
# File lib/e-builder/base.rb, line 338
def setup_close(env, status, header, body)
  return unless body.respond_to? :close and env.include? 'async.close'
  env['async.close'].callback { body.close }
  env['async.close'].errback { body.close }
end