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

Zero-overhead Task wrapper executing a stored callable. More...

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

Inheritance diagram for dfx::Runtime::ASyncTask< Func >:
[legend]
Collaboration diagram for dfx::Runtime::ASyncTask< Func >:
[legend]

Public Member Functions

 ASyncTask (Func func, int priority=0)
 Construct a task executing func.
void run () override
 Execute the task.
Public Member Functions inherited from dfx::Runtime::Task
 Task (int priority=0)
 Construct a task with a given scheduling priority.
 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 Func>
requires std::invocable<Func>
class dfx::Runtime::ASyncTask< Func >

Zero-overhead Task wrapper executing a stored callable.

Template Parameters
FuncCallable type stored by value. Must not take any parameter and the return value is ignored.

ASyncTask is a concrete Task implementation that wraps a callable object of type Func and invokes it in run().

Unlike a type-erased wrapper (e.g. std::function / std::move_only_function), this task is templated on the callable type and stores it directly. This yields:

  • no dynamic allocation for the callable storage (beyond the task allocation itself),
  • no virtual dispatch / type-erasure overhead inside the callable,
  • support for move-only callables (as long as Func itself is movable).

This makes ASyncTask a good building block for the runtime Scheduler / ThreadPool, where many small work items are dispatched frequently and overhead matters.

Warning
The callable runs on a worker thread. If it blocks or runs for a long time, it will occupy that worker and may delay other runtime work.

Constructor & Destructor Documentation

◆ ASyncTask()

template<typename Func>
dfx::Runtime::ASyncTask< Func >::ASyncTask ( Func func,
int priority = 0 )
inline

Construct a task executing func.

The callable is stored by value (moved into the task).

Parameters
funcCallable to store and invoke when the task runs.
priorityScheduling priority for this task (see Task::priority()).

Member Function Documentation

◆ run()

template<typename Func>
void dfx::Runtime::ASyncTask< Func >::run ( )
inlineoverridevirtual

Execute the task.

Called by the runtime when the task is selected for execution. Implementations should keep execution time reasonable and avoid blocking indefinitely to prevent starving other work.

Implements dfx::Runtime::Task.


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