File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2929#define SDBUS_CXX_AWAITABLE_H_
3030
3131#include < atomic>
32+ #include < cassert>
3233#if __has_include(<coroutine>)
3334#include < coroutine>
3435#endif
3839#include < type_traits>
3940#include < variant>
4041
41- namespace sdbus
42- {
42+ namespace sdbus {
43+
44+ // Forward declarations
45+ class AsyncMethodInvoker ;
46+ namespace internal {
47+ class Proxy ;
48+ } // namespace internal
4349
4450/* *******************************************/ /* *
4551 * @enum AwaitableState
@@ -100,14 +106,8 @@ struct AwaitableData
100106template <typename T>
101107class Awaitable
102108{
103- public:
104- explicit Awaitable (std::shared_ptr<AwaitableData<T>> data)
105- : data_(std::move(data))
106- {
107- }
108-
109109#ifdef __cpp_lib_coroutine
110-
110+ public:
111111 // Called when the coroutine is co_await'ed. Returns true if the coroutine should be suspended.
112112 [[nodiscard]] bool await_ready () const noexcept
113113 {
@@ -136,10 +136,18 @@ class Awaitable
136136 else
137137 return std::get<T>(std::move (data_->result ));
138138 }
139-
140139#endif // __cpp_lib_coroutine
141140
142141private:
142+ friend internal::Proxy;
143+ friend AsyncMethodInvoker;
144+
145+ explicit Awaitable (std::shared_ptr<AwaitableData<T>> data)
146+ : data_(std::move(data))
147+ {
148+ assert (data_ != nullptr );
149+ }
150+
143151 std::shared_ptr<AwaitableData<T>> data_;
144152};
145153
You can’t perform that action at this time.
0 commit comments