# FTXUI: task_runner.hpp Source File

Loading...
Searching...
No Matches
task_runner.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_RUNNER_HPP
#define TASK_RUNNER_HPP
#include "ftxui/component/task_internal.hpp"
#include "ftxui/component/task_queue.hpp"
namespace ftxui::task {
class TaskRunner {
public:
TaskRunner();
~TaskRunner();
// Returns the task runner for the current thread.
static auto Current() -> TaskRunner*;
/// Schedules a task to be executed immediately.
auto PostTask(Task task) -> void;
/// Schedules a task to be executed after a certain duration.
auto PostDelayedTask(Task task, std::chrono::steady_clock::duration duration)
-> void;
/// Runs the tasks in the queue, return the delay until the next delayed task
/// can be executed.
auto RunUntilIdle() -> std::optional<std::chrono::steady_clock::duration>;
// Runs the tasks in the queue, blocking until all tasks are executed.
auto Run() -> void;
bool HasImmediateTasks() const { return queue_.HasImmediateTasks(); }
size_t ExecutedTasks() const { return executed_tasks_; }
private:
TaskRunner* previous_task_runner_ = nullptr;
TaskQueue queue_;
size_t executed_tasks_ = 0;
};
} // namespace ftxui::task
#endif // TASK_RUNNER_HPP
ftxui::task::TaskRunner
Definition task_runner.hpp:12
ftxui::task::TaskRunner::HasImmediateTasks
bool HasImmediateTasks() const
Definition task_runner.hpp:34
ftxui::task::TaskRunner::Current
static auto Current() -> TaskRunner *
Definition task_runner.cpp:24
ftxui::task::TaskRunner::Run
auto Run() -> void
Definition task_runner.cpp:62
ftxui::task::TaskRunner::PostTask
auto PostTask(Task task) -> void
Schedules a task to be executed immediately.
Definition task_runner.cpp:29
ftxui::task::TaskRunner::RunUntilIdle
auto RunUntilIdle() -> std::optional< std::chrono::steady_clock::duration >
Runs the tasks in the queue.
Definition task_runner.cpp:40
ftxui::task::TaskRunner::PostDelayedTask
auto PostDelayedTask(Task task, std::chrono::steady_clock::duration duration) -> void
Schedules a task to be executed after a certain duration.
Definition task_runner.cpp:33
ftxui::task::TaskRunner::TaskRunner
TaskRunner()
Definition task_runner.cpp:13
ftxui::task::TaskRunner::ExecutedTasks
size_t ExecutedTasks() const
Definition task_runner.hpp:36
ftxui::task::TaskRunner::~TaskRunner
~TaskRunner()
Definition task_runner.cpp:19
ftxui::task
Definition screen_interactive.hpp:27
ftxui::task::Task
std::function< void()> Task
A task represents a unit of work.
Definition task_internal.hpp:14
ftxui::task::TaskQueue
Definition task_queue.hpp:21
ftxui::task::TaskQueue::HasImmediateTasks
bool HasImmediateTasks() const
Definition task_queue.hpp:28
task_internal.hpp
task_queue.hpp