8#include <boost/assert.hpp>
10#include <fmt/format.h>
58 virtual void setHandle(std::coroutine_handle<> handle) {
60 throw UvcoException(
"PromiseCore is already awaited or has finished");
88 [[nodiscard]]
bool ready()
const {
return slot.has_value(); }
92 [[nodiscard]]
bool stale()
const {
124 std::optional<std::variant<T, std::exception_ptr>>
slot;
133 static_assert(
sizeof(std::coroutine_handle<>) <=
sizeof(
void *),
134 "coroutine_handle is unusually large");
154 void setHandle(std::coroutine_handle<> handle);
161 [[nodiscard]]
bool ready()
const;
163 [[nodiscard]]
bool stale()
const;
169 void except(std::exception_ptr exc);
172 void setRunning(std::coroutine_handle<> handle);
189 std::optional<std::exception_ptr> exception_;
static void cancel(std::coroutine_handle<> handle)
Definition loop.cc:104
static void enqueue(std::coroutine_handle<> handle)
Definition loop.cc:94
Definition promise_core.h:45
void destroyCoroutine()
Definition promise_core.h:114
PromiseCore(const PromiseCore &)=delete
std::coroutine_handle coroutine_
Definition promise_core.h:129
bool ready() const
Checks if a value is present in the slot.
Definition promise_core.h:88
virtual ~PromiseCore()=default
bool stale() const
Definition promise_core.h:92
PromiseState state_
Definition promise_core.h:135
void except(const std::exception_ptr &exc)
Definition promise_core.h:121
PromiseCore(T &&value)
Definition promise_core.h:54
void resume()
Definition promise_core.h:100
std::coroutine_handle waitingHandle_
Definition promise_core.h:132
virtual void setHandle(std::coroutine_handle<> handle)
Set the coroutine to be resumed once a result is ready.
Definition promise_core.h:58
bool isAwaited()
Checks if a coroutine is waiting on a promise belonging to this core.
Definition promise_core.h:85
void resetHandle()
Definition promise_core.h:74
std::optional< std::variant< T, std::exception_ptr > > slot
The slot contains the result once obtained.
Definition promise_core.h:124
PromiseCore & operator=(PromiseCore &&)=delete
void setRunning(std::coroutine_handle<> handle)
Used by Coroutine<T> to set the producing coroutine handle.
Definition promise_core.h:67
PromiseCore & operator=(const PromiseCore &)=delete
PromiseCore(PromiseCore &&)=delete
PromiseState
Definition promise_core.h:31
@ waitedOn
Definition promise_core.h:37
@ finished
Definition promise_core.h:40
@ init
Definition promise_core.h:34
Definition async_work.cc:18
Definition exception.h:19