7#include "../macros.hpp"
10#include "awaitable.hpp"
11#include "awaitable_timer_intf.hpp"
14hi_export_module(hikogui.dispatch.async_task);
16hi_export
namespace hi {
24template<
typename Func,
typename... Args>
25[[nodiscard]] std::invoke_result_t<Func, Args...>
async_task(Func func, Args... args)
requires(is_invocable_task_v<Func, Args...>)
36template<
typename Func,
typename... Args>
37[[nodiscard]] task<std::invoke_result_t<Func, Args...>>
async_task(Func func, Args... args)
38 requires(not is_invocable_task_v<Func, Args...>)
40 using namespace std::literals;
46 if (not future.valid()) {
51 switch (future.wait_for(0s)) {
52 case std::future_status::deferred:
54 co_return future.get();
56 case std::future_status::ready:
57 co_return future.get();
59 case std::future_status::timeout:
94template<
typename Func,
typename... Args>
107template<
typename Func,
typename... Args>
111template<
typename ResultType,
typename FuncType,
typename... ArgTypes>
115 } -> std::same_as<ResultType>;
118template<
typename ResultType,
typename FuncType,
typename... ArgTypes>
122 } -> std::same_as<ResultType>;
125template<
typename ResultType,
typename FuncType,
typename... ArgTypes>
129 } -> std::same_as<ResultType>;
132template<
typename ResultType,
typename FuncType,
typename... ArgTypes>
134 requires(FuncType f, std::stop_token st, progress_token pt, ArgTypes... args) {
137 } -> std::same_as<ResultType>;
140template<
typename ResultType,
typename FuncType,
typename... ArgTypes>
144 } -> std::same_as<task<ResultType>>;
147template<
typename ResultType,
typename FuncType,
typename... ArgTypes>
151 } -> std::same_as<task<ResultType>>;
154template<
typename ResultType,
typename FuncType,
typename... ArgTypes>
158 } -> std::same_as<task<ResultType>>;
161template<
typename ResultType,
typename FuncType,
typename... ArgTypes>
163 requires(FuncType f, std::stop_token st, progress_token pt, ArgTypes... args) {
166 } -> std::same_as<task<ResultType>>;
172template<
typename ResultType,
typename FuncType,
typename... ArgTypes>
196template<
typename Func,
typename... Args>
214 hi_static_no_default();
The HikoGUI namespace.
Definition array_generic.hpp:20
constexpr auto cancel_features_v
The value of the hi::cancel_features<> type trait.
Definition async_task.hpp:108
cancel_features_type
Features of an invocable.
Definition async_task.hpp:71
@ none
This invocable does not have extra arguments.
@ stop_and_progress
The extra arguments are a std::stop_token, followed by a hi::progress_token.
@ progress
The extra argument is a hi::progress_token.
@ stop
The extra argument is a std::stop_token.
std::invoke_result_t< Func, Args... > async_task(Func func, Args... args)
Run a function asynchronously as a co-routine task.
Definition async_task.hpp:25
auto cancelable_async_task(Func func, std::stop_token stop_token, ::hi::progress_token progress_token, Args... args)
Run a function asynchronously as a co-routine task.
Definition async_task.hpp:197
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Type trait to retrieve the cancel feautes of a invokable.
Definition async_task.hpp:95
Token to pass to a function to report its progress.
Definition progress.hpp:23
Definition async_task.hpp:112
Definition async_task.hpp:119
Definition async_task.hpp:126
Definition async_task.hpp:133
Definition async_task.hpp:141
Definition async_task.hpp:148
Definition async_task.hpp:155
Definition async_task.hpp:162
A concept for a callable that may be use in cancelable_async_task().
Definition async_task.hpp:173