Sha256: daf2104d936059236b0dc93a7195258af8bae6e932679712ec0b6b1d9db5b9cc

Contents?: true

Size: 1010 Bytes

Versions: 4

Compression:

Stored size: 1010 Bytes

Contents

require 'rest-core/middleware'

require 'cool.io-http'

class RestCore::CoolioAsync
  include RestCore::Middleware
  def call env
    client = ::Coolio::Http.request(:method  => env[REQUEST_METHOD] ,
                                    :url     => request_uri(env)    ,
                                    :payload => env[REQUEST_PAYLOAD],
                                    :headers => env[REQUEST_HEADERS]){ |res|

      env[TIMER].detach if env[TIMER]
      env[ASYNC].call(env.merge(RESPONSE_BODY    => res.body  ,
                                RESPONSE_STATUS  => res.status,
                                RESPONSE_HEADERS => res.headers)) if
        env[ASYNC]
    }

    env[TIMER].on_timer{
      detach
      client.detach
      env[ASYNC].call(env.merge(RESPONSE_BODY    => env[TIMER].error,
                                RESPONSE_STATUS  => 0               ,
                                RESPONSE_HEADERS => {}             )) if
         env[ASYNC]
    } if env[TIMER]

    env
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-core-1.0.3 lib/rest-core/app/coolio-async.rb
rest-core-1.0.2 lib/rest-core/app/coolio-async.rb
rest-core-1.0.1 lib/rest-core/app/coolio-async.rb
rest-core-1.0.0 lib/rest-core/app/coolio-async.rb