class EmmyHttp::Operation
Attributes
adapter[R]
connection[R]
request[R]
response[R]
Public Class Methods
new(request, adapter, connection=nil)
click to toggle source
# File lib/emmy_http/operation.rb, line 12 def initialize(request, adapter, connection=nil) raise "invalid adapter" if adapter.nil? || !adapter.respond_to?(:to_a) || !adapter.respond_to?(:delegate=) @request = request @connection = connection @adapter = adapter @adapter.delegate = self end
Public Instance Methods
await()
click to toggle source
# File lib/emmy_http/operation.rb, line 28 def await Fiber.await do |fiber| # create connection connect on :init do |connection| # update connection @connection = connection end on :head do |response, operation, conn| # set response @response = response end on :success do |response, operation, conn| # return response fiber.resume response end on :error do |error, operation, conn| # return error as exception if request.raise_error? fiber.leave ConnectionError, error.to_s else fiber.resume nil end end end end
connect()
click to toggle source
# File lib/emmy_http/operation.rb, line 20 def connect @connection ||= EmmyMachine.connect(*self) end
reconnect()
click to toggle source
# File lib/emmy_http/operation.rb, line 24 def reconnect EmmyMachine.reconnect(*self) end
serializable_hash()
click to toggle source
# File lib/emmy_http/operation.rb, line 63 def serializable_hash { request: request.serializable_hash, response: response && response.serializable_hash } end
to_a()
click to toggle source
# File lib/emmy_http/operation.rb, line 59 def to_a adapter.to_a end