Class: GRPC::BidiCall
- Inherits:
-
Object
- Object
- GRPC::BidiCall
- Includes:
- Core::StatusCodes, Core::CallOps, Core::TimeConsts
- Defined in:
- lib/grpc/generic/bidi_call.rb
Overview
The BiDiCall class orchestrates exection of a BiDi stream on a client or server.
Constant Summary
Constants included from Core::CallOps
Core::CallOps::RECV_CLOSE_ON_SERVER, Core::CallOps::RECV_INITIAL_METADATA, Core::CallOps::RECV_MESSAGE, Core::CallOps::RECV_STATUS_ON_CLIENT, Core::CallOps::SEND_CLOSE_FROM_CLIENT, Core::CallOps::SEND_INITIAL_METADATA, Core::CallOps::SEND_MESSAGE, Core::CallOps::SEND_STATUS_FROM_SERVER
Instance Method Summary collapse
-
#initialize(call, q, marshal, unmarshal, deadline) ⇒ BidiCall
constructor
Creates a BidiCall.
-
#run_on_client(requests, &blk) ⇒ Object
Begins orchestration of the Bidi stream for a client sending requests.
-
#run_on_server(gen_each_reply) ⇒ Object
Begins orchestration of the Bidi stream for a server generating replies.
Methods included from Core::TimeConsts
Constructor Details
#initialize(call, q, marshal, unmarshal, deadline) ⇒ BidiCall
Creates a BidiCall.
BidiCall should only be created after a call is accepted. That means different things on a client and a server. On the client, the call is accepted after call.invoke. On the server, this is after call.accept.
#initialize cannot determine if the call is accepted or not; so if a call that’s not accepted is used here, the error won’t be visible until the BidiCall#run is called.
deadline is the absolute deadline for the call.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/grpc/generic/bidi_call.rb', line 60 def initialize(call, q, marshal, unmarshal, deadline) fail(ArgumentError, 'not a call') unless call.is_a? Core::Call unless q.is_a? Core::CompletionQueue fail(ArgumentError, 'not a CompletionQueue') end @call = call @cq = q @deadline = deadline @marshal = marshal @readq = Queue.new @unmarshal = unmarshal end |
Instance Method Details
#run_on_client(requests, &blk) ⇒ Object
Begins orchestration of the Bidi stream for a client sending requests.
The method either returns an Enumerator of the responses, or accepts a block that can be invoked with each response.
80 81 82 83 84 |
# File 'lib/grpc/generic/bidi_call.rb', line 80 def run_on_client(requests, &blk) @enq_th = Thread.new { write_loop(requests) } @loop_th = start_read_loop each_queued_msg(&blk) end |
#run_on_server(gen_each_reply) ⇒ Object
Begins orchestration of the Bidi stream for a server generating replies.
N.B. gen_each_reply is a func(Enumerable<Requests>)
It takes an enumerable of requests as an arg, in case there is a relationship between the stream of requests and the stream of replies.
This does not mean that must necessarily be one. E.g, the replies produced by gen_each_reply could ignore the received_msgs
97 98 99 100 101 |
# File 'lib/grpc/generic/bidi_call.rb', line 97 def run_on_server(gen_each_reply) replys = gen_each_reply.call(each_queued_msg) @loop_th = start_read_loop write_loop(replys, is_client: false) end |