Commit b6b67ac9 authored by Xavier Thompson's avatar Xavier Thompson

typon.hpp: Add optimized fork overloads

parent 81addd67
......@@ -7,6 +7,7 @@
#include <typon/forked.hpp>
#include <typon/future.hpp>
#include <typon/join.hpp>
#include <typon/meta.hpp>
#include <typon/mutex.hpp>
#include <typon/promise.hpp>
#include <typon/root.hpp>
......@@ -25,6 +26,25 @@ namespace typon
co_return co_await std::move(local_task);
}
template <typename Task>
Fork<void> fork(Task task, meta::Empty)
{
// Put the task in a local variable to ensure its destructor will
// be called on co_return instead of only on coroutine destruction.
Task local_task = std::move(task);
co_await std::move(local_task);
}
template <typename Task>
Fork<void> fork(Task task, typename Task::promise_type::value_type & into)
{
// Put the task in a local variable to ensure its destructor will
// be called on co_return instead of only on coroutine destruction.
Task local_task = std::move(task);
// The caller is responsible for garanteeing that the lifetime of
// referenced object will always encompass the lifetime of the fork.
into = co_await std::move(local_task);
}
template <typename Task>
Future<typename Task::promise_type::value_type> future(Task task)
......
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