FTXUI 7.0.3
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/// 一個 task 代表一個工作單位。
14using Task = std::function<void()>;
15
16/// PendingTask 代表一個預計在特定時間或盡快執行的任務。
18 // 立即執行的 task:
19 PendingTask(Task t) : task(std::move(t)) {} // NOLINT
20
21 // 延遲一段時間執行的 task
22 PendingTask(Task t, std::chrono::steady_clock::duration duration)
23 : task(std::move(t)), time(std::chrono::steady_clock::now() + duration) {}
24
25 /// 要執行的 task。
27
28 /// task 應該被執行的時間。如果時間為空,則該 task
29 /// 應該盡快執行。
30 std::optional<std::chrono::steady_clock::time_point> time;
31
32 /// 根據時間比較兩個 PendingTask。
33 /// 如果兩個任務都沒有時間,則視為相等。
34 bool operator<(const PendingTask& other) const;
35};
36
37} // namespace ftxui::task
38
39#endif // TASK_HPP_
std::function< void()> Task
一個 task 代表一個工作單位。
PendingTask 代表一個預計在特定時間或盡快執行的任務。
PendingTask(Task t, std::chrono::steady_clock::duration duration)
Task task
要執行的 task。
std::optional< std::chrono::steady_clock::time_point > time
bool operator<(const PendingTask &other) const
Definition task.cpp:7