Class: GrpcKit::Calls::Client::BidiStreamer

Inherits:
GrpcKit::Calls::Call show all
Defined in:
lib/grpc_kit/calls/client_bidi_streamer.rb

Instance Attribute Summary

Attributes inherited from GrpcKit::Calls::Call

#metadata, #method, #method_name, #service_name

Instance Method Summary collapse

Methods inherited from GrpcKit::Calls::Call

#deadline, #normal_mode, #restrict_mode

Constructor Details

#initializeBidiStreamer

Returns a new instance of BidiStreamer


10
11
12
13
14
# File 'lib/grpc_kit/calls/client_bidi_streamer.rb', line 10

def initialize(*)
  super
  @mutex = Mutex.new
  @send = false
end

Instance Method Details

#close_and_sendObject


58
59
60
61
62
# File 'lib/grpc_kit/calls/client_bidi_streamer.rb', line 58

def close_and_send
  @mutex.synchronize do
    @stream.close_and_send
  end
end

#recv(last: false) ⇒ Object

This method not is expected to be call in the main thread where #send_msg is called

Parameters:

  • last (Boolean)

Returns:

  • (Object)

    response object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/grpc_kit/calls/client_bidi_streamer.rb', line 37

def recv(last: false)
  raise 'No method error' if @restrict

  sleep 0.1 until @send

  loop do
    msg = @mutex.synchronize do
      @stream.recv_msg(last: last, 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, last: false) ⇒ void

This method returns an undefined value.

Parameters:

  • data (Object)

    request message

  • last (Boolean)

19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/grpc_kit/calls/client_bidi_streamer.rb', line 19

def send_msg(data, last: false)
  raise 'No method error' if @restrict

  if @reason
    raise "Upstream returns an error status: #{@reason}"
  end

  @mutex.synchronize do
    @stream.send_msg(data, last: last, metadata: )
  end

  @send = true
end