Class: GrpcKit::Calls::Client::BidiStreamer
- Inherits:
-
GrpcKit::Call
- Object
- GrpcKit::Call
- GrpcKit::Calls::Client::BidiStreamer
- Includes:
- Enumerable
- Defined in:
- lib/grpc_kit/calls/client_bidi_streamer.rb
Instance Attribute Summary
Attributes inherited from GrpcKit::Call
#metadata, #method, #method_name, #service_name
Instance Method Summary collapse
- #close_and_send ⇒ Object
- #each {|response| ... } ⇒ Object
-
#initialize ⇒ BidiStreamer
constructor
A new instance of BidiStreamer.
-
#recv ⇒ Object
This method not is expected to be call in the main thread where #send_msg is called.
- #send_msg(data) ⇒ void
Methods inherited from GrpcKit::Call
Constructor Details
#initialize ⇒ BidiStreamer
Returns a new instance of BidiStreamer.
13 14 15 16 17 |
# File 'lib/grpc_kit/calls/client_bidi_streamer.rb', line 13 def initialize(*) super @mutex = Mutex.new @send = false end |
Instance Method Details
#close_and_send ⇒ Object
55 56 57 58 59 |
# File 'lib/grpc_kit/calls/client_bidi_streamer.rb', line 55 def close_and_send @mutex.synchronize do @stream.close_and_send end end |
#each {|response| ... } ⇒ Object
62 63 64 |
# File 'lib/grpc_kit/calls/client_bidi_streamer.rb', line 62 def each loop { yield(recv) } end |
#recv ⇒ Object
This method not is expected to be call in the main thread where #send_msg is called
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/grpc_kit/calls/client_bidi_streamer.rb', line 36 def recv sleep 0.1 until @send loop do msg = @mutex.synchronize do @stream.recv_msg(blocking: false) end unless msg == :wait_readable return msg end end raise StopIteration rescue GrpcKit::Errors::BadStatus => e @reason = e raise e end |
#send_msg(data) ⇒ void
This method returns an undefined value.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/grpc_kit/calls/client_bidi_streamer.rb', line 21 def send_msg(data) if @reason raise "Upstream returns an error status: #{@reason}" end @mutex.synchronize do @stream.send_msg(data, metadata: ) end @send = true end |