HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions
hi::v1::task_controller< ResultType > Class Template Reference

#include <hikogui/dispatch/task_controller.hpp>

Public Types

using result_type = ResultType
 The result type returned by a hi::task or function.
 
using callback_type = notifier<>::callback_type
 

Public Member Functions

 task_controller (task_controller const &)=delete
 
 task_controller (task_controller &&)=delete
 
task_controlleroperator= (task_controller const &)=delete
 
task_controlleroperator= (task_controller &&)=delete
 
 task_controller () noexcept
 Create a new task_controller.
 
template<typename Func , typename... Args>
requires compatible_cancelable_async_callable<ResultType, Func, Args...>
 task_controller (Func &&func, Args &&... args)
 Create a new task_controller with a assigned coroutine or function and its arguments.
 
template<typename Func , typename... Args>
requires compatible_cancelable_async_callable<ResultType, Func, Args...>
void set_function (Func &&func, Args &&... args)
 Set the coroutine or function and its arguments.
 
void unset_function ()
 Remove the task, so that it can no longer be run.
 
cancel_features_type features () const noexcept
 The features of the coroutine or function that was assigned.
 
bool runnable () const noexcept
 Check if a function is assigned.
 
bool started () const noexcept
 Check if the function was started.
 
bool running () const noexcept
 Check if the function is currently running.
 
bool done () const noexcept
 Check if the function has completed.
 
void reset ()
 Reset the state of the function to not-started.
 
void run ()
 Run the assigned coroutine or function with the previous given arguments.
 
bool request_stop () noexcept
 Request stop.
 
float_t progress () const noexcept
 Get progress of a function.
 
result_type value () const
 Get the return value from the coroutine or function.
 
template<typename Callback >
hi::notifier ::callback_type subscribe (Callback &&callback, callback_flags flags=callback_flags::synchronous)
 Register a callback to be called when a coroutine or function reports progress.
 

Detailed Description

template<typename ResultType>
class hi::v1::task_controller< ResultType >

A task controller.

Template Parameters
ResultTypeThe type of the result of a hi::task or function.

Member Typedef Documentation

◆ result_type

template<typename ResultType >
using hi::v1::task_controller< ResultType >::result_type = ResultType

The result type returned by a hi::task or function.

Constructor & Destructor Documentation

◆ task_controller() [1/2]

template<typename ResultType >
hi::v1::task_controller< ResultType >::task_controller ( )
inlinenoexcept

Create a new task_controller.

◆ task_controller() [2/2]

template<typename ResultType >
template<typename Func , typename... Args>
requires compatible_cancelable_async_callable<ResultType, Func, Args...>
hi::v1::task_controller< ResultType >::task_controller ( Func && func,
Args &&... args )
inline

Create a new task_controller with a assigned coroutine or function and its arguments.

Parameters
funcThe coroutine or function to execute when run() is called.
argsThe arguments passed to the function when run() is called.

Member Function Documentation

◆ done()

template<typename ResultType >
bool hi::v1::task_controller< ResultType >::done ( ) const
inlinenoexcept

Check if the function has completed.

◆ features()

template<typename ResultType >
cancel_features_type hi::v1::task_controller< ResultType >::features ( ) const
inlinenoexcept

The features of the coroutine or function that was assigned.

Returns
none, stop, progress or stop_and_progress.

◆ progress()

template<typename ResultType >
float_t hi::v1::task_controller< ResultType >::progress ( ) const
inlinenoexcept

Get progress of a function.

Precondition
The assigned coroutine or function must accept a hi::progress_token.
Returns
The current progress as reported by the coroutine or function through the hi::progress_token.

◆ request_stop()

template<typename ResultType >
bool hi::v1::task_controller< ResultType >::request_stop ( )
inlinenoexcept

Request stop.

Precondition
The assigned coroutine or function must accept a std::stop_token.
Postcondition
The coroutine or function is requested to stop.

◆ reset()

template<typename ResultType >
void hi::v1::task_controller< ResultType >::reset ( )
inline

Reset the state of the function to not-started.

Exceptions
hi::task_running_errorwhen the function is currently running.

◆ run()

template<typename ResultType >
void hi::v1::task_controller< ResultType >::run ( )
inline

Run the assigned coroutine or function with the previous given arguments.

◆ runnable()

template<typename ResultType >
bool hi::v1::task_controller< ResultType >::runnable ( ) const
inlinenoexcept

Check if a function is assigned.

◆ running()

template<typename ResultType >
bool hi::v1::task_controller< ResultType >::running ( ) const
inlinenoexcept

Check if the function is currently running.

◆ set_function()

template<typename ResultType >
template<typename Func , typename... Args>
requires compatible_cancelable_async_callable<ResultType, Func, Args...>
void hi::v1::task_controller< ResultType >::set_function ( Func && func,
Args &&... args )
inline

Set the coroutine or function and its arguments.

Parameters
funcThe coroutine or function to execute when run() is called.
argsThe arguments passed to the function when run() is called.
Exceptions
hi::task_running_errorwhen the task is currently running.

◆ started()

template<typename ResultType >
bool hi::v1::task_controller< ResultType >::started ( ) const
inlinenoexcept

Check if the function was started.

◆ subscribe()

template<typename ResultType >
template<typename Callback >
hi::notifier ::callback_type hi::v1::task_controller< ResultType >::subscribe ( Callback && callback,
callback_flags flags = callback_flags::synchronous )
inline

Register a callback to be called when a coroutine or function reports progress.

◆ unset_function()

template<typename ResultType >
void hi::v1::task_controller< ResultType >::unset_function ( )
inline

Remove the task, so that it can no longer be run.

Exceptions
hi::task_running_errorwhen the task is currently running.

◆ value()

template<typename ResultType >
result_type hi::v1::task_controller< ResultType >::value ( ) const
inline

Get the return value from the coroutine or function.

Precondition
done() must return true.
Returns
The value returned by return or co_return.

The documentation for this class was generated from the following file: