BewareMyPower commented on code in PR #537:
URL: https://github.com/apache/pulsar-client-cpp/pull/537#discussion_r2762416427
##########
lib/MultiTopicsConsumerImpl.cc:
##########
@@ -850,17 +850,17 @@ void
MultiTopicsConsumerImpl::getBrokerConsumerStatsAsync(const BrokerConsumerSt
LatchPtr latchPtr =
std::make_shared<Latch>(numberTopicPartitions_->load());
lock.unlock();
- size_t i = 0;
- consumers_.forEachValue([this, &latchPtr, &statsPtr, &i, callback](const
ConsumerImplPtr& consumer) {
- size_t index = i++;
- auto weakSelf = weak_from_this();
- consumer->getBrokerConsumerStatsAsync([this, weakSelf, latchPtr,
statsPtr, index, callback](
- Result result, const
BrokerConsumerStats& stats) {
- auto self = weakSelf.lock();
- if (self) {
- handleGetConsumerStats(result, stats, latchPtr, statsPtr,
index, callback);
- }
- });
+ auto indexPtr = std::make_shared<std::atomic<size_t>>(0);
+ auto weakSelf = weak_from_this();
+ consumers_.forEachValue([weakSelf, latchPtr, statsPtr, indexPtr,
callback](const ConsumerImplPtr& consumer) {
Review Comment:
The lambda of `getBrokerConsumerStatsAsync` captures all variables by value:
```c++
consumer->getBrokerConsumerStatsAsync([this, weakSelf, latchPtr, statsPtr,
index, callback](
```
--
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]