RobertIndie commented on code in PR #54:
URL: https://github.com/apache/pulsar-client-cpp/pull/54#discussion_r1000412496
##########
lib/ConsumerImpl.cc:
##########
@@ -1018,66 +1035,31 @@ void ConsumerImpl::closeAsync(ResultCallback callback) {
ClientConnectionPtr cnx = getCnx().lock();
if (!cnx) {
- state_ = Closed;
// If connection is gone, also the consumer is closed on the broker
side
- if (callback) {
- callback(ResultOk);
- }
+ callback(ResultOk);
return;
}
- ClientImplPtr client = client_.lock();
- if (!client) {
- state_ = Closed;
- // Client was already destroyed
- if (callback) {
- callback(ResultOk);
- }
- return;
- }
+ int requestId = client_.newRequestId();
- int requestId = client->newRequestId();
- Future<Result, ResponseData> future =
- cnx->sendRequestWithId(Commands::newCloseConsumer(consumerId_,
requestId), requestId);
- if (callback) {
- // Pass the shared pointer "ptr" to the handler to prevent the object
from being destroyed
- future.addListener(std::bind(&ConsumerImpl::handleClose,
get_shared_this_ptr(), std::placeholders::_1,
- callback, ptr));
- }
-
- // fail pendingReceive callback
- failPendingReceiveCallback();
- failPendingBatchReceiveCallback();
+ auto self = get_shared_this_ptr();
+ cnx->sendRequestWithId(Commands::newCloseConsumer(consumerId_, requestId),
requestId)
+ .addListener([this, self, callback](Result result, const
ResponseData&) { callback(result); });
Review Comment:
Not sure why this caused a compilation error on my computer, but it's fine
in the CI.
```
ConsumerImpl.cc:1047:23: error: lambda capture 'this' is not used
[-Werror,-Wunused-lambda-capture]
.addListener([this, self, callback](Result result, const
ResponseData&) { callback(result); });
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]