make clear independence of bidi streams in route guide client

pull/8151/head
Alexander Polcyn 8 years ago
parent 689e89c2e6
commit b06d534121
  1. 22
      examples/ruby/route_guide/route_guide_client.rb

@ -140,10 +140,24 @@ ROUTE_CHAT_NOTES = [
def run_route_chat(stub)
p 'Route Chat'
p '----------'
# TODO: decouple sending and receiving, i.e have the response enumerator run
# on its own thread.
resps = stub.route_chat(ROUTE_CHAT_NOTES)
resps.each { |r| p "received #{r.inspect}" }
sleeping_enumerator = SleepingEnumerator.new(ROUTE_CHAT_NOTES, 1)
stub.route_chat(sleeping_enumerator.each_item) { |r| p "received #{r.inspect}" }
end
# SleepingEnumerator yields through items, and sleeps between each one
class SleepingEnumerator
def initialize(items, delay)
@items = items
@delay = delay
end
def each_item
return enum_for(:each_item) unless block_given?
@items.each do |item|
sleep @delay
p "next item to send is #{item.inspect}"
yield item
end
end
end
def main

Loading…
Cancel
Save