Class: Protobuf::Rpc::Connectors::EventMachine
- Defined in:
- lib/protobuf/rpc/connectors/eventmachine.rb
Instance Attribute Summary
Attributes inherited from Base
#complete_cb, #failure_cb, #options, #success_cb
Instance Method Summary collapse
-
#ensure_cb ⇒ Object
Returns a callable that ensures any errors will be returned to the client.
- #log_signature ⇒ Object
- #send_request ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Protobuf::Rpc::Connectors::Base
Instance Method Details
#ensure_cb ⇒ Object
Returns a callable that ensures any errors will be returned to the client
If a failure callback was set, just use that as a direct assignment otherwise implement one here that simply throws an exception, since we don't want to swallow the black holes.
32 33 34 |
# File 'lib/protobuf/rpc/connectors/eventmachine.rb', line 32 def ensure_cb @ensure_cb ||= (@failure_cb || lambda { |error| raise '%s: %s' % [error.code.name, error.] } ) end |
#log_signature ⇒ Object
36 37 38 |
# File 'lib/protobuf/rpc/connectors/eventmachine.rb', line 36 def log_signature @log_signature ||= "client-#{self.class}" end |
#send_request ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/protobuf/rpc/connectors/eventmachine.rb', line 9 def send_request ensure_em_running do f = Fiber.current EM.next_tick do log_debug "[#{log_signature}] Scheduling EventMachine client request to be created on next tick" cnxn = EMClient.connect(, &ensure_cb) cnxn.on_success(&success_cb) if success_cb cnxn.on_failure(&ensure_cb) cnxn.on_complete { resume_fiber(f) } unless async? log_debug "[#{log_signature}] Connection scheduled" end async? ? true : set_timeout_and_validate_fiber end end |