FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
task_runner.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_RUNNER_HPP
5#define TASK_RUNNER_HPP
6
9
10namespace ftxui::task {
11
13 public:
14 TaskRunner();
16
17 // 回傳目前執行緒的 task runner。
18 static auto Current() -> TaskRunner*;
19
20 /// 排程一個立即執行的 task。
21 auto PostTask(Task task) -> void;
22
23 /// 排程一個在一段時間後執行的 task。
24 auto PostDelayedTask(Task task, std::chrono::steady_clock::duration duration)
25 -> void;
26
27 /// 執行佇列中的 task,回傳延遲到下一個延遲 task
28 /// 可執行的時間。
29 auto RunUntilIdle() -> std::optional<std::chrono::steady_clock::duration>;
30
31 // 執行佇列中的 task,阻塞直到所有 task 都執行完畢。
32 auto Run() -> void;
33
34 bool HasImmediateTasks() const { return queue_.HasImmediateTasks(); }
35
36 size_t ExecutedTasks() const { return executed_tasks_; }
37
38 private:
39 TaskRunner* previous_task_runner_ = nullptr;
40 TaskQueue queue_;
41 size_t executed_tasks_ = 0;
42};
43
44} // namespace ftxui::task
45
46#endif // TASK_RUNNER_HPP
bool HasImmediateTasks() const
static auto Current() -> TaskRunner *
auto PostTask(Task task) -> void
排程一個立即執行的 task。
auto RunUntilIdle() -> std::optional< std::chrono::steady_clock::duration >
執行佇列中的 task。
auto PostDelayedTask(Task task, std::chrono::steady_clock::duration duration) -> void
排程一個在一段時間後執行的 task。
size_t ExecutedTasks() const
std::function< void()> Task
一個 task 代表一個工作單位。
auto HasImmediateTasks() const -> bool