Fixed coroutine cleanup.
This commit is contained in:
parent
dabaf6d903
commit
ae5e73aa58
@ -49,6 +49,44 @@ class TaskLoop;
|
|||||||
template<typename TResult = void>
|
template<typename TResult = void>
|
||||||
class TaskBase;
|
class TaskBase;
|
||||||
|
|
||||||
|
namespace impl
|
||||||
|
{
|
||||||
|
struct TaskCancelled : std::exception {};
|
||||||
|
|
||||||
|
inline void throwIfCancelled();
|
||||||
|
} // namespace impl
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct TaskState
|
||||||
|
{
|
||||||
|
Optional<T> value;
|
||||||
|
std::exception_ptr exception;
|
||||||
|
TaskStatus status = TaskStatus::SUSPENDED;
|
||||||
|
|
||||||
|
TaskState() = default;
|
||||||
|
TaskState(const TaskState&) = default;
|
||||||
|
TaskState(TaskState&&) noexcept = default;
|
||||||
|
inline TaskState(T _value, TaskStatus _status) noexcept : value(std::move(_value)), status(_status) {}
|
||||||
|
inline TaskState(std::exception_ptr _exception) noexcept : exception(std::move(_exception)), status(TaskStatus::FINISHED) {}
|
||||||
|
TaskState& operator=(const TaskState&) = default;
|
||||||
|
TaskState& operator=(TaskState&&) noexcept = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct TaskState<void>
|
||||||
|
{
|
||||||
|
std::exception_ptr exception;
|
||||||
|
TaskStatus status = TaskStatus::SUSPENDED;
|
||||||
|
|
||||||
|
TaskState() = default;
|
||||||
|
TaskState(const TaskState&) = default;
|
||||||
|
TaskState(TaskState&&) noexcept = default;
|
||||||
|
inline TaskState(TaskStatus _status) noexcept : status(_status) {}
|
||||||
|
inline TaskState(std::exception_ptr _exception) noexcept : exception(std::move(_exception)), status(TaskStatus::FINISHED) {}
|
||||||
|
TaskState& operator=(const TaskState&) = default;
|
||||||
|
TaskState& operator=(TaskState&&) noexcept = default;
|
||||||
|
};
|
||||||
|
|
||||||
namespace impl
|
namespace impl
|
||||||
{
|
{
|
||||||
template<typename TReturn, typename TPromise>
|
template<typename TReturn, typename TPromise>
|
||||||
@ -79,41 +117,7 @@ struct TaskReturn<void, TPromise>
|
|||||||
(static_cast<TPromise&>(*this).state_) = TaskState<void>(std::current_exception());
|
(static_cast<TPromise&>(*this).state_) = TaskState<void>(std::current_exception());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
struct TaskCancelled : std::exception {};
|
|
||||||
|
|
||||||
inline void throwIfCancelled();
|
|
||||||
} // namespace impl
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct TaskState
|
|
||||||
{
|
|
||||||
Optional<T> value;
|
|
||||||
std::exception_ptr exception;
|
|
||||||
TaskStatus status = TaskStatus::SUSPENDED;
|
|
||||||
|
|
||||||
TaskState() = default;
|
|
||||||
TaskState(const TaskState&) = default;
|
|
||||||
TaskState(TaskState&&) noexcept = default;
|
|
||||||
inline TaskState(T _value, TaskStatus _status) noexcept : value(std::move(_value)), status(_status) {}
|
|
||||||
inline TaskState(std::exception_ptr _exception) noexcept : exception(std::move(_exception)), status(TaskStatus::FINISHED) {}
|
|
||||||
TaskState& operator=(const TaskState&) = default;
|
|
||||||
TaskState& operator=(TaskState&&) noexcept = default;
|
|
||||||
};
|
|
||||||
template<>
|
|
||||||
struct TaskState<void>
|
|
||||||
{
|
|
||||||
std::exception_ptr exception;
|
|
||||||
TaskStatus status = TaskStatus::SUSPENDED;
|
|
||||||
|
|
||||||
TaskState() = default;
|
|
||||||
TaskState(const TaskState&) = default;
|
|
||||||
TaskState(TaskState&&) noexcept = default;
|
|
||||||
inline TaskState(TaskStatus _status) noexcept : status(_status) {}
|
|
||||||
inline TaskState(std::exception_ptr _exception) noexcept : exception(std::move(_exception)), status(TaskStatus::FINISHED) {}
|
|
||||||
TaskState& operator=(const TaskState&) = default;
|
|
||||||
TaskState& operator=(TaskState&&) noexcept = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename TValue>
|
template<typename TValue>
|
||||||
struct TaskAwaitableFuture
|
struct TaskAwaitableFuture
|
||||||
@ -304,7 +308,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
constexpr explicit TaskBase(handle_t handle) noexcept : handle_(handle) {}
|
constexpr explicit TaskBase(handle_t handle) noexcept : handle_(handle) {}
|
||||||
TaskBase(const TaskBase&) = delete;
|
TaskBase(const TaskBase&) = delete;
|
||||||
TaskBase(TaskBase&& other) noexcept = default;
|
TaskBase(TaskBase&& other) noexcept : handle_(std::exchange(other.handle_, nullptr)) {}
|
||||||
~TaskBase() noexcept;
|
~TaskBase() noexcept;
|
||||||
public:
|
public:
|
||||||
TaskBase& operator=(const TaskBase&) = default;
|
TaskBase& operator=(const TaskBase&) = default;
|
||||||
@ -548,7 +552,7 @@ TaskBase<TResult>::~TaskBase() noexcept
|
|||||||
{
|
{
|
||||||
if (handle_)
|
if (handle_)
|
||||||
{
|
{
|
||||||
// handle_.destroy();
|
handle_.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user