BewareMyPower commented on code in PR #23:
URL: https://github.com/apache/pulsar-client-cpp/pull/23#discussion_r1010287985
##########
lib/MultiTopicsConsumerImpl.cc:
##########
@@ -647,6 +647,41 @@ void MultiTopicsConsumerImpl::acknowledgeAsync(const
MessageId& msgId, ResultCal
}
}
+void MultiTopicsConsumerImpl::acknowledgeAsync(const MessageIdList&
messageIdList, ResultCallback callback) {
+ if (state_ != Ready) {
+ callback(ResultAlreadyClosed);
+ return;
+ }
+
+ std::unordered_map<std::string, MessageIdList> topicToMessageId;
+ for (const MessageId& messageId : messageIdList) {
+ auto topicName = messageId.getTopicName();
+ topicToMessageId[topicName].emplace_back(messageId);
+ }
+
+ auto needCallBack =
std::make_shared<std::atomic<int>>(topicToMessageId.size());
+ Result res = ResultOk;
+ auto cb = [callback, needCallBack, &res](Result result) {
+ if (result != ResultOk) {
+ res = result;
+ }
+ needCallBack->fetch_sub(1);
+ if (needCallBack->load() == 0) {
+ callback(res);
+ }
Review Comment:
You can test this example:
```c++
#include <chrono>
#include <iostream>
#include <thread>
using namespace std;
void f() {
int x = 0;
int a[1]; // do nothing
std::thread t([&x] {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
cout << std::this_thread::get_id() << " " << &x << " " << x << endl;
});
t.detach();
cout << std::this_thread::get_id() << " " << &x << " " << x << endl;
}
int main() {
f();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
```
```bash
$ g++ 1.cc -std=c++11 -pthread
$ ./a.out
140118122346304 0x7ffffa28a90c 0
140118122342144 0x7ffffa28a90c 32623
$ ./a.out
139920470566720 0x7fffd23f916c 0
139920470562560 0x7fffd23f916c 32767
```
--
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]