10 template<
typename Result,
typename ErrorType>
30 inline auto
valid() const noexcept;
39 inline auto
error() const noexcept -> ErrorType;
45 inline auto operator co_await() & noexcept;
51 inline auto operator co_await() && noexcept;
57 bool _continue_on_error;
59 inline AwaitableBase(
CoroutineType coro,
bool continue_on_error)
noexcept;
61 inline bool await_ready()
const noexcept;
62 inline auto await_suspend(
66 template<
typename ResultType>
67 inline auto await_suspend(
71 inline auto await_suspend(
80 template<
typename Result,
typename ErrorType>
81 inline TaskExpected<Result, ErrorType>::AwaitableBase::AwaitableBase(
83 bool continue_on_error
86 , _continue_on_error{ continue_on_error }
90 template<
typename Result,
typename ErrorType>
91 inline bool TaskExpected<Result, ErrorType>::AwaitableBase::await_ready() const noexcept
93 return !_coroutine || _coroutine.done();
96 template<
typename Result,
typename ErrorType>
101 _coroutine.promise().set_continuation(awaiting_coroutine);
102 _coroutine.promise()._error_continuation = awaiting_coroutine.promise()._error_continuation;
103 _coroutine.promise()._error_pointer = awaiting_coroutine.promise()._error_pointer;
107 template<
typename Result,
typename ErrorType>
108 template<
typename ResultType>
113 _coroutine.promise().set_continuation(awaiting_coroutine);
114 _coroutine.promise()._error_continuation = awaiting_coroutine.promise()._error_continuation;
115 _coroutine.promise()._error_pointer = awaiting_coroutine.promise()._error_pointer;
119 template<
typename Result,
typename ErrorType>
124 _coroutine.promise()._error_continuation = awaiting_coroutine;
125 _coroutine.promise().set_continuation(awaiting_coroutine);
129 template<
typename Result,
typename ErrorType>
134 template<
typename Result,
typename ErrorType>
139 _coroutine.destroy();
143 template<
typename Result,
typename ErrorType>
145 : _coroutine{ ice::exchange(other._coroutine,
nullptr) }
148 template<
typename Result,
typename ErrorType>
153 if (_coroutine !=
nullptr)
155 _coroutine.destroy();
158 _coroutine = ice::exchange(other._coroutine,
nullptr);
164 template<
typename Result,
typename ErrorType>
167 struct TaskAwaitable : AwaitableBase
169 using AwaitableBase::AwaitableBase;
171 auto await_ready()
const noexcept
177 auto await_resume()
const noexcept ->
decltype(
auto)
180 this->_coroutine.operator
bool(),
181 "Broken promise on coroutine TaskExpected!"
188 return TaskAwaitable{ _coroutine,
true };
191 template<
typename Result,
typename ErrorType>
195 return this->_coroutine.promise().result();
198 template<
typename Result,
typename ErrorType>
202 return ice::move(this->_coroutine.promise().result());
205 template<
typename Result,
typename ErrorType>
209 ice::TaskState const state = this->_coroutine.promise()._info->state;
212 if constexpr (std::is_same_v<ErrorType, ice::ErrorCode>)
224 return this->_coroutine.promise()._error_value;
227 template<
typename Result,
typename ErrorType>
230 struct TaskAwaitable : AwaitableBase
232 using AwaitableBase::AwaitableBase;
234 auto await_resume()
const noexcept ->
decltype(
auto)
237 this->_coroutine.operator
bool(),
238 "Broken promise on coroutine TaskExpected!"
241 if constexpr (std::is_same_v<ValueType, void> ==
false)
243 return this->_coroutine.promise().expected();
248 return TaskAwaitable{ _coroutine,
false };
251 template<
typename Result,
typename ErrorType>
254 struct TaskAwaitable : AwaitableBase
256 using AwaitableBase::AwaitableBase;
258 auto await_resume()
const noexcept ->
decltype(
auto)
261 this->_coroutine.operator
bool(),
262 "Broken promise on coroutine TaskExpected!"
265 if constexpr (std::is_same_v<ValueType, void> ==
false)
267 return this->_coroutine.promise().expected_moved();
272 return TaskAwaitable{ ice::move(_coroutine),
false };
275 template<
typename Result,
typename ErrorType>
283template<
typename Result,
typename ErrorType,
typename... Args>
284struct std::coroutine_traits<
ice::TaskExpected<Result, ErrorType>, Args...>
#define ICE_ASSERT(condition, message,...)
Definition assert.hxx:29
#define ICE_ASSERT_CORE(expression)
Definition assert_core.hxx:43
SPDX-License-Identifier: MIT.
Definition array.hxx:12
TaskState
All states a task can be in.
Definition task_info.hxx:13
@ Canceled
Task was canceled at any point of it's lifetime.
Definition task_info.hxx:32
@ Succeeded
Task finished execution with a valid result.
Definition task_info.hxx:29
@ Failed
Task finished execution but results are invalid.
Definition task_info.hxx:35
static constexpr ice::ErrorCode E_TaskCanceled
Definition error_codes.hxx:22
constexpr bool has_any(T value, T expected_flags) noexcept
Definition enum_flags.hxx:83
std::coroutine_handle< Type > coroutine_handle
Definition task_types.hxx:42
constexpr bool has_none(T value, T expected_flags) noexcept
Definition enum_flags.hxx:89
ice::Expected< ice::ErrorCode > Result
Definition expected.hxx:197
Definition task_expected.hxx:12
~TaskExpected() noexcept
Definition task_expected.hxx:135
ice::coroutine_handle< PromiseType > CoroutineType
Definition task_expected.hxx:16
TaskExpected(CoroutineType coro=nullptr) noexcept
Definition task_expected.hxx:130
ice::TaskExpectedPromise< Result, ErrorType > PromiseType
Definition task_expected.hxx:15
auto valid() const noexcept
Definition task_expected.hxx:165
auto result() &noexcept -> Result &
Definition task_expected.hxx:192
auto operator=(TaskExpected const &) noexcept=delete
Result ValueType
Definition task_expected.hxx:14
auto error() const noexcept -> ErrorType
Definition task_expected.hxx:206
Definition task_expected_promise.hxx:17
auto get_return_object() noexcept -> ice::TaskExpected< Result, ErrorType >
Definition task_expected.hxx:276
typename ice::TaskExpected< Result, ErrorType >::PromiseType promise_type
Definition task_expected.hxx:286