Sha256: 0d1b47fb7c6e656d5ea5ae2cfdd3511abc7bfc54600ba0579e607e992f8c0978
Contents?: true
Size: 1.54 KB
Versions: 39
Compression:
Stored size: 1.54 KB
Contents
module Isomorfeus module Transport class RequestAgent class << self def agents @_agents ||= {} end def get(object_id) agents[object_id] end def del!(object_id) agents.delete(object_id.to_s) end end attr_accessor :processed attr_accessor :result attr_accessor :response attr_accessor :full_response attr_accessor :sent attr_accessor :queued attr_reader :id attr_reader :promise attr_reader :request def initialize(request = nil) @id = object_id.to_s self.class.agents[@id] = self current_agent = self @promise = Promise.new @promise.then do Isomorfeus::Transport.unregister_request_in_progress(current_agent.id) Isomorfeus::Transport::RequestAgent.del!(current_agent.id) end @promise.fail do |e| STDERR.puts "#{e}" Isomorfeus::Transport.unregister_request_in_progress(current_agent.id) Isomorfeus::Transport::RequestAgent.del!(current_agent.id) end @request = request @sent = false end def process(&block) return self.result if self.processed self.processed = true Isomorfeus.raise_error(message: self.response[:error]) if self.response.key?(:error) self.result = block.call(self) @promise.resolve(self) unless @promise.realized? self.result end end end end
Version data entries
39 entries across 39 versions & 1 rubygems