Commit 8e6211d3 authored by Xavier Thompson's avatar Xavier Thompson

Add Drop policy to optimize void / ignored results

parent c8f49ef0
......@@ -79,13 +79,45 @@ namespace typon
};
};
struct Drop
{
void on_final_suspend(std::coroutine_handle<> coroutine) noexcept
{
coroutine.destroy();
}
struct OnAwaitable
{
Span * _span;
Span::u64 _rank;
template <typename Promise>
void on_await_suspend(std::coroutine_handle<Promise> coroutine) noexcept
{
_span = coroutine.promise()._span;
_rank = _span->_thefts;
}
template <typename Promise>
void on_await_resume(std::coroutine_handle<Promise> coroutine)
{
if (_span->_thefts == _rank)
{
Defer defer { [coroutine]() { coroutine.destroy(); } };
coroutine.promise().get();
}
}
};
};
}
template <typename T = void, typename Policy = policy::Refcnt>
template <typename T = void, typename P = policy::Refcnt>
struct [[nodiscard]] Fork
{
struct promise_type;
using u64 = Span::u64;
using Policy = std::conditional_t<std::is_same_v<T, void>, policy::Drop, P>;
std::coroutine_handle<promise_type> _coroutine;
......
......@@ -89,28 +89,6 @@ namespace typon
};
template <>
struct ForkResult<void>
{
ForkNode * _node {nullptr};
template <typename Promise>
void construct_value(std::coroutine_handle<Promise> coroutine)
{
coroutine.promise().get();
}
void construct_value(ForkResult && other) noexcept
{
(void) other;
}
void get_value() noexcept {}
void destroy_value() noexcept {}
};
template <typename T>
struct Forked : ForkResult<T>
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment