9#include <boost/assert.hpp>
11#include <fmt/format.h>
74 virtual void setHandle(std::coroutine_handle<> handle) {
76 throw UvcoException(
"PromiseCore is already awaited or has finished");
99 BOOST_ASSERT(!
ready());
103 slot = std::make_exception_ptr(
115 [[nodiscard]]
bool ready()
const {
return slot.has_value(); }
153 "PromiseCore::resume() called without handle in state waitedOn");
169 "PromiseCore destroyed without ever being resumed ({}, state = {})\n",
170 typeid(T).name(),
static_cast<int>(
state_));
184 std::optional<std::variant<T, std::exception_ptr>>
slot;
187 std::optional<std::coroutine_handle<>>
handle_;
207 void setHandle(std::coroutine_handle<> handle);
214 [[nodiscard]]
bool ready()
const;
216 [[nodiscard]]
bool stale()
const;
222 void except(std::exception_ptr exc);
232 std::optional<std::coroutine_handle<>>
handle_;
static void enqueue(std::coroutine_handle<> handle)
Definition loop.cc:73
PromiseCore(PromiseCore &&)=delete
std::optional< std::exception_ptr > exception_
Contains the exception if thrown.
Definition promise_core.h:229
PromiseCore(const PromiseCore &)=delete
std::optional< std::coroutine_handle<> > handle_
Definition promise_core.h:232
PromiseCore< void > & operator=(PromiseCore &&)=delete
PromiseCore< void > & operator=(const PromiseCore &)=delete
Definition promise_core.h:61
virtual ~PromiseCore()
Definition promise_core.h:165
PromiseCore(const PromiseCore &)=delete
bool ready() const
Checks if a value is present in the slot.
Definition promise_core.h:115
bool stale() const
Definition promise_core.h:118
std::optional< std::coroutine_handle<> > handle_
Definition promise_core.h:187
PromiseState state_
Definition promise_core.h:188
void except(const std::exception_ptr &exc)
Definition promise_core.h:181
PromiseCore(T &&value)
Definition promise_core.h:70
void cancel()
Definition promise_core.h:97
bool willResume()
Checks if a coroutine is waiting on a promise belonging to this core.
Definition promise_core.h:113
virtual void setHandle(std::coroutine_handle<> handle)
Set the coroutine to be resumed once a result is ready.
Definition promise_core.h:74
void resetHandle()
Definition promise_core.h:84
std::optional< std::variant< T, std::exception_ptr > > slot
The slot contains the result once obtained.
Definition promise_core.h:184
PromiseCore & operator=(PromiseCore &&)=delete
PromiseCore & operator=(const PromiseCore &)=delete
virtual void resume()
Definition promise_core.h:126
PromiseCore(PromiseCore &&)=delete
Definition internal_utils.h:98
PromiseState
Definition promise_core.h:34
Definition async_work.cc:17
Definition exception.h:19