@@ -157,15 +157,14 @@ class AsyncReadStreamImpl
157157 context_ = std::move (context);
158158 cq_ = std::move (cq);
159159 auto callback = std::make_shared<NotifyStart>(this ->shared_from_this ());
160- void * tag = cq_->RegisterOperation (std::move (callback));
161- // @note If `tag == nullptr` the `CompletionQueue` has been `Shutdown()`.
162- // We leave `reader_` null in this case; other methods must make the
163- // same `tag != nullptr` check prior to accessing `reader_`. This is
164- // safe since `Shutdown()` cannot be undone.
165- if (tag != nullptr ) {
160+ cq_->StartOperation (std::move (callback), [&](void * tag) {
161+ // @note If the the `CompletionQueue` has been `Shutdown()` this lambda is
162+ // never called. We leave `reader_` null in this case; other methods
163+ // must make the same `tag != nullptr` check prior to accessing
164+ // `reader_`. This is safe since `Shutdown()` cannot be undone.
166165 reader_ = async_call (context_.get (), request, &cq_->cq ());
167166 reader_->StartCall (tag);
168- }
167+ });
169168 }
170169
171170 // / Cancel the current streaming read RPC.
@@ -202,10 +201,8 @@ class AsyncReadStreamImpl
202201
203202 auto callback = std::make_shared<NotifyRead>(this ->shared_from_this ());
204203 auto response = &callback->response ;
205- void * tag = cq_->RegisterOperation (std::move (callback));
206- if (tag != nullptr ) {
207- reader_->Read (response, tag);
208- }
204+ cq_->StartOperation (std::move (callback),
205+ [&](void * tag) { reader_->Read (response, tag); });
209206 }
210207
211208 // / Handle the result of a `Read()` call.
@@ -252,10 +249,8 @@ class AsyncReadStreamImpl
252249
253250 auto callback = std::make_shared<NotifyFinish>(this ->shared_from_this ());
254251 auto status = &callback->status ;
255- void * tag = cq_->RegisterOperation (std::move (callback));
256- if (tag != nullptr ) {
257- reader_->Finish (status, tag);
258- }
252+ cq_->StartOperation (std::move (callback),
253+ [&](void * tag) { reader_->Finish (status, tag); });
259254 }
260255
261256 // / Handle the result of a Finish() request.
@@ -292,10 +287,8 @@ class AsyncReadStreamImpl
292287
293288 auto callback = std::make_shared<NotifyDiscard>(this ->shared_from_this ());
294289 auto response = &callback->response ;
295- void * tag = cq_->RegisterOperation (std::move (callback));
296- if (tag != nullptr ) {
297- reader_->Read (response, tag);
298- }
290+ cq_->StartOperation (std::move (callback),
291+ [&](void * tag) { reader_->Read (response, tag); });
299292 }
300293
301294 // / Handle the result of a Discard() call.
0 commit comments