31 constexpr void return_void() {}
38 template<
typename promise_type>
41 constexpr bool await_ready()
const noexcept {
return false; }
47 if (promise.continuation_)
48 return promise.continuation_;
49 if (promise.exception_)
62 struct ConstantAwaiter {
64 constexpr bool await_ready()
const noexcept {
return true; }
66 T await_resume()
noexcept {
return std::move (value_); }
68 template<
typename T>
decltype(
auto)
69 await_transform (T &&value)
74 else if constexpr (
requires { value.operator
co_await(); })
77 else if constexpr (
requires {
operator co_await (
std::forward<T> (value)); })
82 return ConstantAwaiter<std::remove_cvref_t<T>> {
std::forward<T>(value) };
92template<
typename Result>
103 result_.emplace (std::move (value));
108 result_.emplace (value);
112 constexpr bool await_ready () const noexcept {
return !
frame_ ||
frame_.
done(); }
135 CoTask (CoTask &&o) noexcept :
frame_ (o.frame_) { o.frame_ =
nullptr; }
136 CoTask& operator= (CoTask &&o)
noexcept {
std::swap (
frame_, o.frame_);
return *
this; }
137 CoTask (
const CoTask&) =
delete;
138 CoTask& operator= (
const CoTask&) =
delete;
152 constexpr void return_void()
noexcept {}
155 constexpr bool await_ready () const noexcept {
return !
frame_ ||
frame_.
done(); }
172 CoTask (CoTask &&o) noexcept :
frame_ (o.frame_) { o.frame_ =
nullptr; }
173 CoTask& operator= (CoTask &&o)
noexcept {
std::swap (
frame_, o.frame_);
return *
this; }
174 CoTask (
const CoTask&) =
delete;
175 CoTask& operator= (
const CoTask&) =
delete;
Concept: Is T an awaitable?
T current_exception(T... args)
#define ASE_ASSERT_UNREACHED(...)
Abort and issue an assertion error.
#define ASE_ASSERT_RETURN(expr,...)
Return from the current function if expr evaluates to false and issue an assertion warning.
#define ASE_RETURN_UNLESS(cond,...)
Return silently if cond does not evaluate to true, with return value ...
T from_promise(T... args)
The Anklang C++ API namespace.
void ase_rethrow(std::exception_ptr exception)
Helper to trace rethrown exceptions.
Start a coroutine in fire-and-forget mode.
T noop_coroutine(T... args)
std::coroutine_handle await_suspend(std::coroutine_handle< promise_type > h) noexcept
Resume the parent frame that is co_await-ing this CoTask<>
Like CoTask<Result> without return type.
std::coroutine_handle< promise_type > frame_
Handle for this task.
General purpose coroutine task.
std::coroutine_handle< promise_type > frame_
Handle for this task.