Class: FullDuplexEnumerator

Inherits:
Object
  • Object
show all
Includes:
Grpc::Testing, Grpc::Testing::PayloadType
Defined in:
src/ruby/pb/test/server.rb

Overview

A FullDuplexEnumerator passes requests to a block and yields generated responses

Constant Summary

Constants included from Grpc::Testing

Grpc::Testing::BoolValue, Grpc::Testing::ClientConfigureRequest, Grpc::Testing::ClientConfigureResponse, Grpc::Testing::EchoStatus, Grpc::Testing::Empty, Grpc::Testing::EmptyMessage, Grpc::Testing::GaugeRequest, Grpc::Testing::GaugeResponse, Grpc::Testing::GrpclbRouteType, Grpc::Testing::HookRequest, Grpc::Testing::HookResponse, Grpc::Testing::LoadBalancerAccumulatedStatsRequest, Grpc::Testing::LoadBalancerAccumulatedStatsResponse, Grpc::Testing::LoadBalancerStatsRequest, Grpc::Testing::LoadBalancerStatsResponse, Grpc::Testing::MemorySize, Grpc::Testing::Payload, Grpc::Testing::PayloadType, Grpc::Testing::ReconnectInfo, Grpc::Testing::ReconnectParams, Grpc::Testing::ResponseParameters, Grpc::Testing::SetReturnStatusRequest, Grpc::Testing::SimpleRequest, Grpc::Testing::SimpleResponse, Grpc::Testing::StreamingInputCallRequest, Grpc::Testing::StreamingInputCallResponse, Grpc::Testing::StreamingOutputCallRequest, Grpc::Testing::StreamingOutputCallResponse, Grpc::Testing::TestOrcaReport

Instance Method Summary collapse

Constructor Details

#initialize(requests) ⇒ FullDuplexEnumerator

Returns a new instance of FullDuplexEnumerator.



143
144
145
# File 'src/ruby/pb/test/server.rb', line 143

def initialize(requests)
  @requests = requests
end

Instance Method Details

#each_itemObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'src/ruby/pb/test/server.rb', line 146

def each_item
  return enum_for(:each_item) unless block_given?
  GRPC.logger.info('interop-server: started receiving')
  begin
    cls = StreamingOutputCallResponse
    @requests.each do |req|
      maybe_echo_status_and_message(req)
      req.response_parameters.each do |params|
        resp_size = params.size
        GRPC.logger.info("read a req, response size is #{resp_size}")
        yield cls.new(payload: Payload.new(type: req.response_type,
                                            body: nulls(resp_size)))
      end
    end
    GRPC.logger.info('interop-server: finished receiving')
  rescue StandardError => e
    GRPC.logger.info('interop-server: failed')
    GRPC.logger.warn(e)
    fail e
  end
end