16#include <dfx-runtime-api/Task.hpp>
41 template<
typename Func>
42 requires (!std::same_as<PackagedTask, std::remove_cvref_t<Func>>)
45 , _task { std::forward<Func>(func) }
53 {
return _task.get_future(); }
63 std::packaged_task<R()> _task;
76template<
typename Func,
typename ... Args>
79 using ReturnType = std::invoke_result_t<Func>;
80 return std::make_unique<PackagedTask<ReturnType>>(std::forward<Func>(func), std::forward<Args>(args)...);
Polymorphic unit of work executed by the runtime (typically by ThreadPool).
Definition Task.hpp:48
Task(int priority=0)
Construct a task with a given scheduling priority.
Definition Task.hpp:55
int priority() const noexcept
Task scheduling priority.
Definition Task.hpp:67
PackagedTask(Func &&func, int priority=0)
Constructs a new PackagedTask object.
Definition PackagedTask.hpp:43
void run() override
Executes the wrapped task.
Definition PackagedTask.hpp:59
std::future< R > getFuture()
Gets a future associated with the task's result.
Definition PackagedTask.hpp:52
auto makePackagedTask(Func &&func, Args &&... args)
Helper factory function to create a PackagedTask wrapped in a std::unique_ptr.
Definition PackagedTask.hpp:77