Add reset for std::promise
std::promise needs to be reinitialized for each async operation after std::future is returned
PiperOrigin-RevId: 451236518
diff --git a/internal/platform/implementation/windows/ble_medium.cc b/internal/platform/implementation/windows/ble_medium.cc
index 477f428..55f49e8 100644
--- a/internal/platform/implementation/windows/ble_medium.cc
+++ b/internal/platform/implementation/windows/ble_medium.cc
@@ -14,6 +14,7 @@
#include "internal/platform/implementation/windows/ble_medium.h"
+#include <future> // NOLINT
#include <string>
#include "absl/synchronization/mutex.h"
@@ -97,6 +98,8 @@
publisher_token_ =
publisher_.StatusChanged({this, &BleMedium::PublisherHandler});
+ publisher_started_promise_ = std::promise<PublisherState>();
+
std::future<PublisherState> publisher_state_future =
publisher_started_promise_.get_future();
@@ -110,6 +113,8 @@
NEARBY_LOGS(INFO) << "Windows Ble StopAdvertising: service_id=" << service_id;
+ publisher_stopped_promise_ = std::promise<PublisherState>();
+
std::future<PublisherState> publisher_state_future =
publisher_stopped_promise_.get_future();
@@ -132,6 +137,8 @@
advertisement_received_token_ =
watcher_.Received({this, &BleMedium::AdvertisementReceivedHandler});
+ watcher_started_promise_ = std::promise<WatcherState>();
+
std::future<WatcherState> watcher_state_future =
watcher_started_promise_.get_future();
@@ -154,6 +161,8 @@
NEARBY_LOGS(INFO) << "Windows Ble StopScanning: service_id=" << service_id;
+ watcher_stopped_promise_ = std::promise<WatcherState>();
+
std::future<WatcherState> watcher_state_future =
watcher_stopped_promise_.get_future();