Class: GrpcKit::Streams::Client
- Inherits:
-
Object
- Object
- GrpcKit::Streams::Client
- Defined in:
- lib/grpc_kit/streams/client.rb
Instance Method Summary collapse
- #close_and_recv ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(session:, config:, authority:) ⇒ Client
constructor
A new instance of Client.
- #recv(last: false) ⇒ Object
- #send_msg(data, metadata: {}, timeout: nil, last: false) ⇒ Object
Constructor Details
#initialize(session:, config:, authority:) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 |
# File 'lib/grpc_kit/streams/client.rb', line 10 def initialize(session:, config:, authority:) @config = config @session = session @stream = nil = end |
Instance Method Details
#close_and_recv ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/grpc_kit/streams/client.rb', line 59 def close_and_recv unless @stream raise 'You should call `send` method to send data' end unless @stream.end_write? @session.resume_data(@stream.stream_id) end @stream.end_write @session.start(@stream.stream_id) @stream.end_read check_status! data = [] @stream.each { |d| data.push(d) } data end |
#each(&block) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/grpc_kit/streams/client.rb', line 36 def each(&block) unless @stream raise 'You should call `send` method to send data' end @stream.each(&block) end |
#recv(last: false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/grpc_kit/streams/client.rb', line 44 def recv(last: false) unless @stream raise 'You should call `send` method to send data' end data = @stream.recv(last: last, limit_size: @config.) if data.nil? check_status! raise StopIteration end data end |
#send_msg(data, metadata: {}, timeout: nil, last: false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/grpc_kit/streams/client.rb', line 17 def send_msg(data, metadata: {}, timeout: nil, last: false) if @stream # unless metadata.empty? # raise 'You can attach metadata at first send_msg' # XXX # end unless @stream.end_write? @session.resume_data(@stream.stream_id) end else headers = build_headers(metadata: , timeout: timeout) stream = @session.start_request(GrpcKit::Streams::SendBuffer.new, headers) @stream = GrpcKit::Stream.new(protobuf: @config.protobuf, session: @session, stream: stream) end @stream.send(data, last: last, limit_size: @config.) @session.run_once end |