Class: GrpcKit::Session::Client

Inherits:
DS9::Client
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/grpc_kit/session/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(io, handler, opts = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
# File 'lib/grpc_kit/session/client.rb', line 15

def initialize(io, handler, opts = {})
  super() # initialize DS9::Session

  @io = io
  @streams = {}
  @handler = handler
  @opts = opts
end

Instance Method Details

#run_onceObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/grpc_kit/session/client.rb', line 46

def run_once
  return if @stop

  if want_read?
    do_read
  end

  if want_write?
    send
  end
end

#start(stream_id) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/grpc_kit/session/client.rb', line 32

def start(stream_id)
  stream = @streams.fetch(stream_id)

  loop do
    if (!want_read? && !want_write?) || stream.end_stream?
      break
    end

    run_once
  end
rescue Errno::ECONNRESET, IOError
  finish
end

#start_request(data, headers) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/grpc_kit/session/client.rb', line 24

def start_request(data, headers)
  stream_id = submit_request(headers, data)
  stream = GrpcKit::Session::Stream.new(stream_id: stream_id, send_data: data)
  stream.stream_id = stream_id
  @streams[stream_id] = stream
  stream
end