28 template<
typename T,
typename SubscribeFn = function<prepared_coro(promise<T>)> >
34 using subscribe_fn = SubscribeFn;
36 using canceled_awaiter = _details::has_value_awaiter<subscription,false>;
50 _fn = std::move(other._fn);
62 decltype(
auto)
get() {
return _fut.await_resume();}
81 return _fut.await_resume();
103 template<std::invocable Fn>
105 auto prom = _fut.get_promise();
106 _fut.then(std::forward<Fn>(fn));
107 return std::forward<SubscribeFn>(_fn)(std::move(prom));
115 template<std::invocable Fn>
117 then(std::forward<Fn>(fn));
121 std::atomic<bool> *unlock =
nullptr;
122 void operator()(
auto) {
124 unlock->notify_all();
129 using lock_ptr = std::unique_ptr<std::remove_reference_t<ret_value>, lock_guard>;
144 static constexpr lock_ptr
init_lock(std::atomic<bool> &unlock) {
return lock_ptr{
146 reinterpret_cast<std::remove_reference_t<ret_value> *
>(&unlock), {&unlock}
158 std::atomic<bool> ready = {
false};
159 std::atomic<bool> *unlock =
nullptr;
161 std::atomic<bool> lk;
170 ret_value ref = _fut.get();
171 ptr = lock_ptr(&ref, {unlock});
174 unlock->notify_all();
175 ptr = lock_ptr(
nullptr, {});
promise_t get_promise()
Retrieve promise and begin evaluation.
std::conditional_t< std::is_void_v< T >, void, std::add_rvalue_reference_t< T > > ret_value
type which is used as return value of get() and await_resume()
bool is_pending() const
Determines pending status.
Contains future value of T, can be co_awaited in coroutine.
contains prepared coroutine (prepared to run)
Carries reference to future<T>, callable, sets value of an associated future<T>
subscription(const SubscribeFn &fn)
construct and pass subscribe function
subscription()=default
default constructor
subscription(SubscribeFn &&fn)
construct and pass subscribe function
static constexpr lock_ptr init_lock(std::atomic< bool > &unlock)
initialize lock_ptr, set atomic variable, which receives signal once the thread starts waiting on a s...
prepared_coro then(Fn &&fn)
define callback, which is called when value is ready
ret_value await_resume()
returns current value
void lock(lock_ptr &ptr)
subscribe and lock value during processing
void operator>>(Fn &&fn)
define callback, which is called when value is ready
decltype(auto) get()
retrieve last value
bool has_value() const
Determine, whether has value.
static constexpr bool await_ready() noexcept
co_await support
subscription(subscription &&other)
movable
canceled_awaiter operator!()
wait and determine whether operation is canceled
static constexpr lock_ptr init_lock()
initialize lock_ptr object, which can be used to call lock() to wait on subscription and process resu...
std::coroutine_handle await_suspend(std::coroutine_handle<> h)
co_await support Subscribe and wait for a value
subscription & operator=(subscription &&other)
movable
Awaiter for subscriptions.