FTXUI 6.1.9
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 // Returns the task runner for the current thread.
18 static auto Current() -> TaskRunner*;
19
20 /// Schedules a task to be executed immediately.
21 auto PostTask(Task task) -> void;
22
23 /// Schedules a task to be executed after a certain duration.
24 auto PostDelayedTask(Task task,
25 std::chrono::steady_clock::duration duration) -> void;
26
27 /// Runs the tasks in the queue, return the delay until the next delayed task
28 /// can be executed.
29 auto RunUntilIdle() -> std::optional<std::chrono::steady_clock::duration>;
30
31 // Runs the tasks in the queue, blocking until all tasks are executed.
32 auto Run() -> void;
33
34 bool HasImmediateTasks() const {
35 return queue_.HasImmediateTasks();
36 }
37
38 size_t ExecutedTasks() const { return executed_tasks_; }
39
40 private:
41 TaskRunner* previous_task_runner_ = nullptr;
42 TaskQueue queue_;
43 size_t executed_tasks_ = 0;
44};
45
46} // namespace ftxui::task
47
48
49#endif // TASK_RUNNER_HPP
bool HasImmediateTasks() const
static auto Current() -> TaskRunner *
auto PostTask(Task task) -> void
Schedules a task to be executed immediately.
auto RunUntilIdle() -> std::optional< std::chrono::steady_clock::duration >
Runs the tasks in the queue.
auto PostDelayedTask(Task task, std::chrono::steady_clock::duration duration) -> void
Schedules a task to be executed after a certain duration.
size_t ExecutedTasks() const
std::function< void()> Task
A task represents a unit of work.
bool HasImmediateTasks() const