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)), time(std::chrono::steady_clock::now() + duration) {}
25
26 /// The task to be executed.
28
29 /// The time when the task should be executed. If the time is empty, the task
30 /// should be executed as soon as possible.
31 std::optional<std::chrono::steady_clock::time_point> time;
32
33 /// Compare two PendingTasks by their time.
34 /// If both tasks have no time, they are considered equal.
35 bool operator<(const PendingTask& other) const;
36};
37
38} // namespace ftxui::task
39
40#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