HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions
v1::scoped_task< T > Class Template Reference

#include <hikogui/scoped_task.hpp>

Data Structures

struct  promise_type
 

Public Types

using value_type = T
 
using return_value_type = std::variant<std::monostate, std::exception_ptr, value_type>
 The return value type.
 
using return_value_ptr_type = std::shared_ptr<return_value_type>
 
using const_return_value_ptr_type = std::shared_ptr<return_value_type const>
 
using notifier_type = notifier<void(value_type)>
 
using handle_type = std::coroutine_handle<promise_type>
 

Public Member Functions

 scoped_task (handle_type coroutine, const_return_value_ptr_type value_ptr) noexcept
 
 scoped_task (scoped_task const &)=delete
 
scoped_taskoperator= (scoped_task const &)=delete
 
 scoped_task (scoped_task &&other) noexcept
 
scoped_taskoperator= (scoped_task &&other) noexcept
 
bool completed () const noexcept
 Check if the co-routine has completed.
 
 operator bool () const noexcept
 Check if the co-routine has completed.
 
value_type const & value () const
 Get the return value returned from co_return.
 
value_type const & operator* () const
 Get the return value returned from co_return.
 
notifier_type::token_type subscribe (std::invocable< value_type > auto &&callback) noexcept
 Subscribe a callback for when the co-routine is completed.
 

Detailed Description

template<typename T = void>
class v1::scoped_task< T >

A scoped_task.

Like the hi::task instance this implements a asynchronous co-routine task.

If the scoped_task object is destroyed, the potentially non-completed co-routine will be destroyed as well. A scoped_task is a move-only object.

Template Parameters
TThe type returned by co_return.

Member Typedef Documentation

◆ return_value_type

template<typename T = void>
using v1::scoped_task< T >::return_value_type = std::variant<std::monostate, std::exception_ptr, value_type>

The return value type.

This value is shared between the promise and the scoped_task. The variant has three different states:

  • 0: co-routine has not completed.
  • 1: co-routine caught an uncaught exception.
  • 2: co-routine is completed with a value.

Member Function Documentation

◆ completed()

template<typename T = void>
bool v1::scoped_task< T >::completed ( ) const
inlinenoexcept

Check if the co-routine has completed.

◆ operator bool()

template<typename T = void>
v1::scoped_task< T >::operator bool ( ) const
inlineexplicitnoexcept

Check if the co-routine has completed.

◆ operator*()

template<typename T = void>
value_type const & v1::scoped_task< T >::operator* ( ) const
inline

Get the return value returned from co_return.

Note
It is undefined behavior to call this function if the co-routine is incomplete.
Exceptions
Theexception thrown from the co-routine.

◆ subscribe()

template<typename T = void>
notifier_type::token_type v1::scoped_task< T >::subscribe ( std::invocable< value_type > auto && callback)
inlinenoexcept

Subscribe a callback for when the co-routine is completed.

Parameters
callbackThe callback to call when the co-routine executed co_return. If co_return has a non-void expression then the callback must accept the expression as an argument.

◆ value()

template<typename T = void>
value_type const & v1::scoped_task< T >::value ( ) const
inline

Get the return value returned from co_return.

Note
It is undefined behavior to call this function if the co-routine is incomplete.
Exceptions
Theexception thrown from the co-routine.

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