diff options
author | Alexander Polcyn <apolcyn@google.com> | 2016-09-20 12:30:55 -0700 |
---|---|---|
committer | Alexander Polcyn <apolcyn@google.com> | 2016-09-20 12:30:55 -0700 |
commit | b06d534121ba3da53bccb474e79da12c5c270f95 (patch) | |
tree | 1329c53d70f8bbbfe93f09a731c29e48d7cdd2a4 | |
parent | 689e89c2e6e7a118046f5bc14aea92e3655e3dfb (diff) |
make clear independence of bidi streams in route guide client
-rwxr-xr-x | examples/ruby/route_guide/route_guide_client.rb | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/examples/ruby/route_guide/route_guide_client.rb b/examples/ruby/route_guide/route_guide_client.rb index 330725ece0..01ea42c186 100755 --- a/examples/ruby/route_guide/route_guide_client.rb +++ b/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 |