FTXUI 6.1.9
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 <queue>
8#include <variant>
9
10#include "ftxui/component/task_internal.hpp" // for PendingTask, Task
11
12namespace ftxui::task {
13
14/// A task queue that schedules tasks to be executed in the future. Tasks can be
15/// scheduled to be executed immediately, or after a certain duration.
16/// - The tasks are executed in the order they were scheduled.
17/// - If multiple tasks are scheduled to be executed at the same time, they are
18/// executed in the order they were scheduled.
19/// - If a task is scheduled to be executed in the past, it is executed
20/// immediately.
21struct TaskQueue {
22 auto PostTask(PendingTask task) -> void;
23
24 using MaybeTask =
25 std::variant<Task, std::chrono::steady_clock::duration, std::monostate>;
26 auto Get() -> MaybeTask;
27
28 bool HasImmediateTasks() const { return !immediate_tasks_.empty(); }
29
30 private:
31 std::queue<PendingTask> immediate_tasks_;
32 std::priority_queue<PendingTask> delayed_tasks_;
33};
34
35} // namespace ftxui::task
36
37#endif
bool HasImmediateTasks() const
auto Get() -> MaybeTask
std::variant< Task, std::chrono::steady_clock::duration, std::monostate > MaybeTask
auto PostTask(PendingTask task) -> void
Definition task_queue.cpp:8