From ec01ed39a715a42e249547728e883b998d1411ab Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Tue, 30 Aug 2022 11:35:00 -0400 Subject: [PATCH] Fix nodiscard warnings in sync client In later C++ versions, std::async is marked nodiscard. See https://cplusplus.github.io/LWG/issue2856. The code is correct in that it is properly blocking for the result, but it will now warn since this is considered "not the way". Adding .wait() to the end of the calls, which explicitly waits on the future, should be the correct fix. Signed-off-by: Daniel Berlin --- src/mqtt/client.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mqtt/client.h b/src/mqtt/client.h index 6900aed6..64fda8a9 100644 --- a/src/mqtt/client.h +++ b/src/mqtt/client.h @@ -68,17 +68,17 @@ class client : private callback // Most are launched in a separate thread, for convenience, except // message_arrived, for performance. void connected(const string& cause) override { - std::async(std::launch::async, &callback::connected, userCallback_, cause); + std::async(std::launch::async, &callback::connected, userCallback_, cause).wait(); } void connection_lost(const string& cause) override { std::async(std::launch::async, - &callback::connection_lost, userCallback_, cause); + &callback::connection_lost, userCallback_, cause).wait(); } void message_arrived(const_message_ptr msg) override { userCallback_->message_arrived(msg); } void delivery_complete(delivery_token_ptr tok) override { - std::async(std::launch::async, &callback::delivery_complete, userCallback_, tok); + std::async(std::launch::async, &callback::delivery_complete, userCallback_, tok).wait(); } /** Non-copyable */