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 <mutex>
8#include <queue>
9#include <variant>
10
11#include "ftxui/component/task_internal.hpp" // for PendingTask, Task
12
13namespace ftxui::task {
14
15/// A task queue that schedules tasks to be executed in the future. Tasks can be
16/// scheduled to be executed immediately, or after a certain duration.
17/// - The tasks are executed in the order they were scheduled.
18/// - If multiple tasks are scheduled to be executed at the same time, they are
19/// executed in the order they were scheduled.
20/// - If a task is scheduled to be executed in the past, it is executed
21/// immediately.
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
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