Method: Calculator#div_many

Defined in:
src/ruby/bin/math_server.rb

#div_many(requests) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'src/ruby/bin/math_server.rb', line 126

def div_many(requests)
  # requests is an lazy Enumerator of the requests sent by the client.
  q = EnumeratorQueue.new(self)
  t = Thread.new do
    begin
      requests.each do |req|
        GRPC.logger.info("read #{req.inspect}")
        resp = Math::DivReply.new(quotient: req.dividend / req.divisor,
                                  remainder: req.dividend % req.divisor)
        q.push(resp)
        Thread.pass  # let the internal Bidi threads run
      end
      GRPC.logger.info('finished reads')
      q.push(self)
    rescue StandardError => e
      q.push(e)  # share the exception with the enumerator
      raise e
    end
  end
  t.priority = -2  # hint that the div_many thread should not be favoured
  q.each_item
end