Class: EventMachine::JsonRPC::Client::Request

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/em-jsonrpc/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, id) ⇒ Request

Returns a new instance of Request.



171
172
173
174
# File 'lib/em-jsonrpc/client.rb', line 171

def initialize(client, id)
  @client = client
  @id = id
end

Instance Method Details

#deleteObject



176
177
178
# File 'lib/em-jsonrpc/client.rb', line 176

def delete
  @client.pending_requests.delete @id
end

#timeout(seconds) ⇒ Object

Override EM::Deferrable#timeout method so the errback is executed passing a :request_timeout single argument. Also, the request is removed from the list of pending requests.



183
184
185
186
187
188
189
190
# File 'lib/em-jsonrpc/client.rb', line 183

def timeout seconds
  cancel_timeout
  me = self
  @deferred_timeout = EM::Timer.new(seconds) do
    me.delete
    me.fail :request_timeout
  end
end