dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Runtime::PackagedTask< R > Class Template Reference

A task implementation that wraps a callable object and provides a future for the result. More...

#include <dfx-runtime/tasks/PackagedTask.hpp>

Inheritance diagram for dfx::Runtime::PackagedTask< R >:
[legend]
Collaboration diagram for dfx::Runtime::PackagedTask< R >:
[legend]

Public Member Functions

template<typename Func>
requires (!std::same_as<PackagedTask, std::remove_cvref_t<Func>>)
 PackagedTask (Func &&func, int priority=0)
 Constructs a new PackagedTask object.
std::future< R > getFuture ()
 Gets a future associated with the task's result.
void run () override
 Executes the wrapped task.
Public Member Functions inherited from dfx::Runtime::Api::Task
 Task (int priority=0)
 Construct a task with a given scheduling priority.
 DFX_DISABLE_COPY_AND_MOVE (Task)
 Tasks are neither copyable nor movable.
virtual ~Task ()=default
 Polymorphic base requires a virtual destructor.
int priority () const noexcept
 Task scheduling priority.
template<DerivedFromTask T>
T & as ()
 Unchecked downcast to a concrete task type.
template<DerivedFromTask T>
T const & as () const
 Unchecked downcast to a concrete task type (const overload).

Detailed Description

template<typename R>
class dfx::Runtime::PackagedTask< R >

A task implementation that wraps a callable object and provides a future for the result.

PackagedTask inherits from the dfx Runtime API Task and integrates with std::future. It allows a callable (function, lambda, etc.) to be executed asynchronously by the runtime while allowing the caller to retrieve the result at a later time.

Template Parameters
RThe return type of the task.

Constructor & Destructor Documentation

◆ PackagedTask()

template<typename R>
template<typename Func>
requires (!std::same_as<PackagedTask, std::remove_cvref_t<Func>>)
dfx::Runtime::PackagedTask< R >::PackagedTask ( Func && func,
int priority = 0 )
inlineexplicit

Constructs a new PackagedTask object.

Template Parameters
FuncThe type of the callable object.
Parameters
funcThe callable object to be executed.
priorityThe execution priority of the task (defaults to 0).
Note
This constructor uses C++20 concepts to ensure it doesn't interfere with copy/move construction.

Member Function Documentation

◆ getFuture()

template<typename R>
std::future< R > dfx::Runtime::PackagedTask< R >::getFuture ( )
inline

Gets a future associated with the task's result.

Returns
std::future<R> A future object that will eventually contain the result of the task execution.

◆ run()

template<typename R>
void dfx::Runtime::PackagedTask< R >::run ( )
inlineoverridevirtual

Executes the wrapped task.

Overrides the pure virtual run() method from Api::Task. This invokes the underlying std::packaged_task.

Implements dfx::Runtime::Api::Task.


The documentation for this class was generated from the following file: