Update description of route_chat method

This commit is contained in:
Sho Ito 2019-11-04 20:14:07 +09:00
parent b7b846bcfa
commit 192c467bc5
1 changed files with 3 additions and 14 deletions

View File

@ -250,26 +250,15 @@ Finally, let's look at our bidirectional streaming RPC `route_chat`.
```ruby
def route_chat(notes)
q = EnumeratorQueue.new(self)
t = Thread.new do
begin
notes.each do |n|
...
end
end
q = EnumeratorQueue.new(self)
...
return q.each_item
RouteChatEnumerator.new(notes, @received_notes).each_item
end
```
Here the method receives an
[Enumerable](https://ruby-doc.org//core-2.2.0/Enumerable.html), but also returns
an [Enumerator](https://ruby-doc.org//core-2.2.0/Enumerator.html) that yields the
responses. The implementation demonstrates how to set these up so that the
requests and responses can be handled concurrently. Although each side will
always get the other's messages in the order they were written, both the client
and server can read and write in any order — the streams operate completely
responses. Although each side will always get the other's messages in the order they were written,
both the client and server can read and write in any order — the streams operate completely
independently.
#### Starting the server