dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
ASyncTask.hpp
1// SPDX-FileCopyrightText: 2025 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard incldes
12#include <concepts>
13
14// Project includes
15#include "Task.hpp"
16
17namespace dfx::Runtime
18{
40template<typename Func>
41requires std::invocable<Func>
42class ASyncTask : public Task
43{
44public:
51 ASyncTask(Func func, int priority = 0)
52 : Task(priority)
53 , _func { std::move(func) }
54 {}
55
56 void run() override
57 { _func(); }
58
59private:
60 Func _func;
61};
62
78template<typename Func, typename ... Args>
79auto makeASyncTask(Func && func, Args && ... args)
80{
81 return std::make_unique<ASyncTask<std::decay_t<Func>>>(std::forward<Func>(func), std::forward<Args>(args)...);
82}
83} // !namespace dfx::Runtime
void run() override
Execute the task.
Definition ASyncTask.hpp:56
ASyncTask(Func func, int priority=0)
Construct a task executing func.
Definition ASyncTask.hpp:51
int priority() const noexcept
Task scheduling priority.
Definition Task.hpp:67
Task(int priority=0)
Construct a task with a given scheduling priority.
Definition Task.hpp:55
Definition Node.hpp:47
auto makeASyncTask(Func &&func, Args &&... args)
Helper to create an ASyncTask with type decay.
Definition ASyncTask.hpp:79
STL namespace.