@@ -36,42 +36,26 @@ inline void CHECK_RESULT(Result res) {
3636 }
3737}
3838
39+ namespace internal {
40+
41+ void waitForResult (std::promise<pulsar::Result>& promise);
42+
43+ } // namespace internal
44+
3945void waitForAsyncResult (std::function<void (ResultCallback)> func);
4046
4147template <typename T>
4248inline T waitForAsyncValue (std::function<void (std::function<void (Result, const T&)>)> func) {
4349 auto resultPromise = std::make_shared<std::promise<Result>>();
4450 auto valuePromise = std::make_shared<std::promise<T>>();
4551
46- std::weak_ptr<std::promise<Result>> weakResultPromise{resultPromise};
47- std::weak_ptr<std::promise<T>> weakValuePromise{valuePromise};
48-
49- func ([weakResultPromise, weakValuePromise](Result result, const T& value) {
50- auto valuePromise = weakValuePromise.lock ();
51- if (valuePromise) {
52- valuePromise->set_value (value);
53- }
54- auto resultPromise = weakResultPromise.lock ();
55- if (resultPromise) {
56- resultPromise->set_value (result);
57- }
52+ func ([resultPromise, valuePromise](Result result, const T& value) {
53+ valuePromise->set_value (value);
54+ resultPromise->set_value (result);
5855 });
5956
60- auto resultFuture = resultPromise->get_future ();
61- while (true ) {
62- {
63- py::gil_scoped_release release;
64- auto status = resultFuture.wait_for (std::chrono::milliseconds (100 ));
65- if (status == std::future_status::ready) {
66- CHECK_RESULT (resultFuture.get ());
67- return valuePromise->get_future ().get ();
68- }
69- }
70- py::gil_scoped_acquire acquire;
71- if (PyErr_CheckSignals () != 0 ) {
72- raiseException (ResultInterrupted);
73- }
74- }
57+ internal::waitForResult (*resultPromise);
58+ return valuePromise->get_future ().get ();
7559}
7660
7761struct CryptoKeyReaderWrapper {
0 commit comments