Skip to content

Commit 341bfc2

Browse files
committed
refactor: make Awaitable c-tor private
1 parent da37295 commit 341bfc2

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

include/sdbus-c++/Awaitable.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define SDBUS_CXX_AWAITABLE_H_
3030

3131
#include <atomic>
32+
#include <cassert>
3233
#if __has_include(<coroutine>)
3334
#include <coroutine>
3435
#endif
@@ -38,8 +39,13 @@
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
100106
template <typename T>
101107
class 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

142141
private:
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

0 commit comments

Comments
 (0)