Skip to content

Commit e8e26d0

Browse files
committed
Added section for the server shutdown
1 parent 479b89b commit e8e26d0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/tutorials/async/helloasync-cpp.md

+22
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,28 @@ runs a main loop in `HandleRpcs` to query the queue:
195195
}
196196
```
197197
198+
### Shutting Down the Server
199+
We've been using a completion queue to get the async notifications. Care must be
200+
taken to shut it down *after* the server has also been shut down.
201+
202+
Remember we got our completion queue instance `cq_` in `ServerImpl::Run()` by
203+
running `cq_ = builder.AddCompletionQueue()`. Looking at
204+
`ServerBuilder::AddCompletionQueue`'s documentation we see that
205+
206+
> ... Caller is required to shutdown the server prior to shutting down the
207+
> returned completion queue.
208+
209+
Refer to `ServerBuilder::AddCompletionQueue`'s full docstring for more details.
210+
What this means in our example is that `ServerImpl's` destructor looks like:
211+
212+
```
213+
~ServerImpl() {
214+
server_->Shutdown();
215+
// Always shutdown the completion queue after the server.
216+
cq_->Shutdown();
217+
}
218+
```
219+
198220
You can see our complete server example in
199221
[greeter_async_server.cc](https://github.com/grpc/grpc/blob/{{
200222
site.data.config.grpc_release_branch

0 commit comments

Comments
 (0)