shibd commented on code in PR #16969:
URL: https://github.com/apache/pulsar/pull/16969#discussion_r940475945
##########
pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc:
##########
@@ -363,13 +401,12 @@ void MultiTopicsConsumerImpl::closeAsync(ResultCallback
callback) {
auto self = shared_from_this();
int numConsumers = 0;
- consumers_.forEach(
- [&numConsumers, &self, callback](const std::string& name, const
ConsumerImplPtr& consumer) {
- numConsumers++;
- consumer->closeAsync([self, name, callback](Result result) {
- self->handleSingleConsumerClose(result, name, callback);
- });
+ for (const auto& item : consumers_.toPairVector()) {
Review Comment:
> The effect of these traversal methods looks the same.
This method is to copy a copy to traverse. If this is not done, a pointer
exception will occur.
> toPairVector is marked with 'only used for tests'.
Maybe need to find another better way, I will look at it again.
##########
pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc:
##########
@@ -363,13 +401,12 @@ void MultiTopicsConsumerImpl::closeAsync(ResultCallback
callback) {
auto self = shared_from_this();
int numConsumers = 0;
- consumers_.forEach(
- [&numConsumers, &self, callback](const std::string& name, const
ConsumerImplPtr& consumer) {
- numConsumers++;
- consumer->closeAsync([self, name, callback](Result result) {
- self->handleSingleConsumerClose(result, name, callback);
- });
+ for (const auto& item : consumers_.toPairVector()) {
Review Comment:
> The effect of these traversal methods looks the same.
This method is to copy a copy to traverse. If this is not done, a pointer
exception will occur.
> toPairVector is marked with 'only used for tests'.
Maybe need to find another better way, I will look at it again.
--
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]