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/coroutine/scoped_task.hpp>

Data Structures

struct  promise_type
 

Public Types

using value_type = T
 
using notifier_type = notifier<void(value_type)>
 
using callback_token = notifier_type::callback_token
 
using callback_proto = notifier_type::callback_proto
 
using handle_type = std::coroutine_handle<promise_type>
 

Public Member Functions

 scoped_task (handle_type coroutine) 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 done () 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.
 
callback_token subscribe (forward_of< callback_proto > auto &&callback, callback_flags flags=callback_flags::synchronous) 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 Function Documentation

◆ done()

template<typename T = void>
bool v1::scoped_task< T >::done ( ) 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>
callback_token v1::scoped_task< T >::subscribe ( forward_of< callback_proto > auto && callback,
callback_flags flags = callback_flags::synchronous )
inlinenoexcept

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

Parameters
flagsThe callback flags used to be passed to the notifier.
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.
Returns
The callback token used to manage the lifetime of the callback

◆ 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: