Class: Hx::Interop::RPC::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/interop/rpc/base.rb

Overview

Base class for RPC Client and Server

Direct Known Subclasses

Client, Server

Instance Method Summary collapse

Constructor Details

#initialize(reader, writer = reader, task_group: TaskGroup.new) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:



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

#waitObject

Wait for the process to finish (i.e. for the connection to close). Does not wait for running requests/event handlers to complete.

Raises:

  • (@error)


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