FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
task_queue.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_QUEUE_HPP
5#define TASK_QUEUE_HPP
6
7#include <mutex>
8#include <queue>
9#include <variant>
10
11#include "ftxui/component/task_internal.hpp" // for PendingTask, Task
12
13namespace ftxui::task {
14
15/// 一個排程 task 在未來執行的 task 佇列。task 可以
16/// 排程為立即執行,或在一段時間後執行。
17/// - task 依照排程的順序執行。
18/// - 如果多個 task 排程在同一時間執行,則依照
19/// 排程的順序執行。
20/// - 如果一個 task 排程在過去執行,它會被
21/// 立即執行。
22struct TaskQueue {
23 using MaybeTask =
24 std::variant<Task, std::chrono::steady_clock::duration, std::monostate>;
25
26 auto Get() -> MaybeTask;
27 auto HasImmediateTasks() const -> bool;
28 auto PostTask(PendingTask task) -> void;
29
30 private:
31 mutable std::mutex mutex_;
32 std::queue<PendingTask> immediate_tasks_;
33 std::priority_queue<PendingTask> delayed_tasks_;
34};
35
36} // namespace ftxui::task
37
38#endif
PendingTask 代表一個預計在特定時間或盡快執行的任務。
auto HasImmediateTasks() const -> bool
auto Get() -> MaybeTask
std::variant< Task, std::chrono::steady_clock::duration, std::monostate > MaybeTask
auto PostTask(PendingTask task) -> void
Definition task_queue.cpp:8