lib/muxer/request.rb in muxer-0.3.3 vs lib/muxer/request.rb in muxer-0.3.4

- old
+ new

@@ -19,13 +19,15 @@ # @!attribute error # @return [Boolean] Have we had an error? # @!attribute id # @return [Symbol] ID for this request, the ID is arbitrary and to # be assigned by the user + # @!attribute runtime + # @return [Float] Runtime for the request class Request attr_accessor :url, :timeout, :headers, :params, :redirects, :id - attr_reader :method, :completed, :error + attr_reader :method, :completed, :error, :runtime alias_method :completed?, :completed def initialize @method = :get @completed = false @@ -54,20 +56,21 @@ # process! executes the web request. It cannot be called from # outside of an EventMachine loop. # # @return self def process! + @start = Time.now http = EventMachine::HttpRequest.new(url, connect_timeout: timeout, inactivity_timeout: timeout, ) @request = http.public_send(method, request_options ) - @request.callback { @completed = true } - @request.errback { @completed = @error = true} + @request.callback { @completed = true; @runtime = Time.now - @start; @start = nil } + @request.errback { @completed = @error = true; @runtime = Time.now - @start; @start = nil} self end # response is the actual http request's response. def response \ No newline at end of file