# FTXUI: task_queue.hpp Source File

Loading...
Searching...
No Matches
task_queue.hpp
Go to the documentation of this file.
// Copyright 2024 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#ifndef TASK_QUEUE_HPP
#define TASK_QUEUE_HPP
#include <queue>
#include <variant>
#include "ftxui/component/task_internal.hpp" // for PendingTask, Task
namespace ftxui::task {
/// A task queue that schedules tasks to be executed in the future. Tasks can be
/// scheduled to be executed immediately, or after a certain duration.
/// - The tasks are executed in the order they were scheduled.
/// - If multiple tasks are scheduled to be executed at the same time, they are
/// executed in the order they were scheduled.
/// - If a task is scheduled to be executed in the past, it is executed
/// immediately.
struct TaskQueue {
auto PostTask(PendingTask task) -> void;
using MaybeTask =
std::variant<Task, std::chrono::steady_clock::duration, std::monostate>;
auto Get() -> MaybeTask;
bool HasImmediateTasks() const { return !immediate_tasks_.empty(); }
private:
std::queue<PendingTask> immediate_tasks_;
std::priority_queue<PendingTask> delayed_tasks_;
};
} // namespace ftxui::task
#endif
ftxui::task
Definition screen_interactive.hpp:27
ftxui::task::PendingTask
Definition task_internal.hpp:18
ftxui::task::TaskQueue
Definition task_queue.hpp:21
ftxui::task::TaskQueue::HasImmediateTasks
bool HasImmediateTasks() const
Definition task_queue.hpp:28
ftxui::task::TaskQueue::Get
auto Get() -> MaybeTask
Definition task_queue.cpp:22
ftxui::task::TaskQueue::MaybeTask
std::variant< Task, std::chrono::steady_clock::duration, std::monostate > MaybeTask
Definition task_queue.hpp:24
ftxui::task::TaskQueue::PostTask
auto PostTask(PendingTask task) -> void
Definition task_queue.cpp:8
task_internal.hpp