Skip to content
Snippets Groups Projects
Commit b06d5341 authored by Alexander Polcyn's avatar Alexander Polcyn
Browse files

make clear independence of bidi streams in route guide client

parent 689e89c2
No related branches found
No related tags found
No related merge requests found
...@@ -140,10 +140,24 @@ ROUTE_CHAT_NOTES = [ ...@@ -140,10 +140,24 @@ ROUTE_CHAT_NOTES = [
def run_route_chat(stub) def run_route_chat(stub)
p 'Route Chat' p 'Route Chat'
p '----------' p '----------'
# TODO: decouple sending and receiving, i.e have the response enumerator run sleeping_enumerator = SleepingEnumerator.new(ROUTE_CHAT_NOTES, 1)
# on its own thread. stub.route_chat(sleeping_enumerator.each_item) { |r| p "received #{r.inspect}" }
resps = stub.route_chat(ROUTE_CHAT_NOTES) end
resps.each { |r| p "received #{r.inspect}" }
# 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 end
def main def main
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment