Class: Hx::Interop::RPC::Base
- Inherits:
-
Object
- Object
- Hx::Interop::RPC::Base
- Defined in:
- lib/interop/rpc/base.rb
Overview
Base class for RPC Client and Server
Instance Method Summary collapse
-
#initialize(reader, writer = reader, task_group: TaskGroup.new) {|_self| ... } ⇒ Base
constructor
A new instance of Base.
- #on(criteria, *handler, &block) ⇒ Object
-
#wait ⇒ Object
Wait for the process to finish (i.e. for the connection to close).
Constructor Details
#initialize(reader, writer = reader, task_group: TaskGroup.new) {|_self| ... } ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/interop/rpc/base.rb', line 11 def initialize(reader, writer = reader, task_group: TaskGroup.new) @connection = Connection.build(reader, writer) @dispatcher = Dispatcher.new @tasks = task_group yield self if block_given? @io_thread = Thread.new do run rescue StandardError => e @error = e end end |
Instance Method Details
#on(criteria, *handler, &block) ⇒ Object
34 35 36 37 |
# File 'lib/interop/rpc/base.rb', line 34 def on(criteria, *handler, &block) @dispatcher.on criteria, *handler, &block self end |
#wait ⇒ Object
Wait for the process to finish (i.e. for the connection to close). Does not wait for running requests/event handlers to complete.
27 28 29 30 31 32 |
# File 'lib/interop/rpc/base.rb', line 27 def wait @io_thread.join raise @error if @error # TODO: wrap in something specific, to preserve backtrace self end |