Implement move-assignment for task<T> and lazy_task<T>.
This commit is contained in:
parent
02188fe727
commit
946d794f9f
2 changed files with 42 additions and 7 deletions
|
@ -285,6 +285,22 @@ namespace cppcoro
|
|||
}
|
||||
}
|
||||
|
||||
lazy_task& operator=(lazy_task&& other) noexcept
|
||||
{
|
||||
if (std::addressof(other) != this)
|
||||
{
|
||||
if (m_coroutine)
|
||||
{
|
||||
m_coroutine.destroy();
|
||||
}
|
||||
|
||||
m_coroutine = other.m_coroutine;
|
||||
other.m_coroutine = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// \brief
|
||||
/// Query if the task result is complete.
|
||||
///
|
||||
|
|
|
@ -294,15 +294,21 @@ namespace cppcoro
|
|||
/// another task).
|
||||
~task()
|
||||
{
|
||||
if (m_coroutine)
|
||||
{
|
||||
if (!m_coroutine.promise().is_ready())
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
m_coroutine.destroy();
|
||||
/// Move assignment.
|
||||
task& operator=(task&& other) noexcept
|
||||
{
|
||||
if (std::addressof(other) != this)
|
||||
{
|
||||
destroy();
|
||||
|
||||
m_coroutine = other.m_coroutine;
|
||||
other.m_coroutine = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// \brief
|
||||
|
@ -389,6 +395,19 @@ namespace cppcoro
|
|||
|
||||
private:
|
||||
|
||||
void destroy() noexcept
|
||||
{
|
||||
if (m_coroutine)
|
||||
{
|
||||
if (!m_coroutine.promise().is_ready())
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
m_coroutine.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
std::experimental::coroutine_handle<promise_type> m_coroutine;
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue