FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
task_internal.hpp
Go to the documentation of this file.
1// Copyright 2024 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#ifndef TASK_HPP
5#define TASK_HPP
6
7#include <chrono>
8#include <functional>
9#include <optional>
10
11namespace ftxui::task {
12
13/// A task represents a unit of work.
14using Task = std::function<void()>;
15
16/// A PendingTask represents a task that is scheduled to be executed at a
17/// specific time, or as soon as possible.
19 // Immediate task:
20 PendingTask(Task t) : task(std::move(t)) {} // NOLINT
21
22 // Delayed task with a duration
23 PendingTask(Task t, std::chrono::steady_clock::duration duration)
24 : task(std::move(t)),
25 time(std::chrono::steady_clock::now() + duration) {}
26
27 /// The task to be executed.
29
30 /// The time when the task should be executed. If the time is empty, the task
31 /// should be executed as soon as possible.
32 std::optional<std::chrono::steady_clock::time_point> time;
33
34 /// Compare two PendingTasks by their time.
35 /// If both tasks have no time, they are considered equal.
36 bool operator<(const PendingTask& other) const;
37};
38
39} // namespace ftxui::task
40
41
42#endif // TASK_HPP_
std::function< void()> Task
A task represents a unit of work.
PendingTask(Task t, std::chrono::steady_clock::duration duration)
Task task
The task to be executed.
std::optional< std::chrono::steady_clock::time_point > time
bool operator<(const PendingTask &other) const
Definition task.cpp:7