Class: VCAP::Services::Api::AsyncHttpRequest
- Inherits:
-
Object
- Object
- VCAP::Services::Api::AsyncHttpRequest
- Defined in:
- lib/services/api/async_requests.rb
Class Method Summary collapse
- .fibered(url, token, verb, timeout, msg = VCAP::Services::Api::EMPTY_REQUEST) ⇒ Object
- .new(url, token, verb, timeout, msg = VCAP::Services::Api::EMPTY_REQUEST) ⇒ Object
Class Method Details
.fibered(url, token, verb, timeout, msg = VCAP::Services::Api::EMPTY_REQUEST) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/services/api/async_requests.rb', line 34 def fibered(url, token, verb, timeout, msg=VCAP::Services::Api::EMPTY_REQUEST) req = new(url, token, verb, timeout, msg) f = Fiber.current req.callback { f.resume(req) } req.errback { f.resume(req) } Fiber.yield end |
.new(url, token, verb, timeout, msg = VCAP::Services::Api::EMPTY_REQUEST) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/services/api/async_requests.rb', line 18 def new(url, token, verb, timeout, msg=VCAP::Services::Api::EMPTY_REQUEST) req = { :head => { VCAP::Services::Api::GATEWAY_TOKEN_HEADER => token, 'Content-Type' => 'application/json', }, :body => msg.encode, } if timeout EM::HttpRequest.new(url, :inactivity_timeout => timeout).send(verb.to_sym, req) else EM::HttpRequest.new(url).send(verb.to_sym, req) end end |