BewareMyPower commented on code in PR #254:
URL: https://github.com/apache/pulsar-client-cpp/pull/254#discussion_r1169417887
##########
tests/c/c_ConsumerTest.cc:
##########
@@ -69,9 +107,17 @@ TEST(c_ConsumerTest, testBatchReceive) {
free(str);
}
+ pulsar_messages_free(msgs);
+
+ std::promise<void> receive_promise;
+ std::future<void> receive_future = receive_promise.get_future();
+ struct batch_receive_ctx batch_receive_ctx = {pulsar_result_UnknownError,
consumer, &receive_promise,
+ batch_receive_max_size};
+ pulsar_consumer_batch_receive_async(consumer, batch_receive_callback,
&batch_receive_ctx);
+ receive_future.get();
+ ASSERT_EQ(pulsar_result_Ok, batch_receive_ctx.result);
Review Comment:
It's better to use `std::promise<pulsar_result>` and check the
`receive_future.get()` is `pulsar_result_Ok` because the callback is called in
another thread and setting a `pulsar_result` in that thread is not thread safe.
--
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]