HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions
v1::notifier< Result(Args...)> Class Template Reference

Data Structures

class  awaiter_type
 An awaiter object which can wait on a notifier. More...
 

Public Types

using result_type = Result
 
using callback_type = std::function<Result(Args const&...)>
 
using token_type = std::shared_ptr<callback_type>
 
using weak_token_type = std::weak_ptr<callback_type>
 

Public Member Functions

constexpr notifier () noexcept=default
 Create a notifier.
 
 notifier (notifier &&)=delete
 
 notifier (notifier const &)=delete
 
notifieroperator= (notifier &&)=delete
 
notifieroperator= (notifier const &)=delete
 
awaiter_type operator co_await () const noexcept
 Create an awaiter that can await on this notifier.
 
token_type subscribe (std::invocable< Args... > auto &&callback) noexcept
 Add a callback to the notifier.
 
void post (Args const &...args) const noexcept
 Post the subscribed callbacks on the current thread's event loop with the given arguments.
 
void post_on_main (Args const &...args) const noexcept
 Post the subscribed callbacks on the main thread's event loop with the given arguments.
 
auto operator() (Args const &...args) const noexcept
 Call the subscribed callbacks with the given arguments.
 

Constructor & Destructor Documentation

◆ notifier()

template<typename Result , typename... Args>
constexpr v1::notifier< Result(Args...)>::notifier ( )
constexprdefaultnoexcept

Create a notifier.

Member Function Documentation

◆ operator co_await()

template<typename Result , typename... Args>
awaiter_type v1::notifier< Result(Args...)>::operator co_await ( ) const
inlinenoexcept

Create an awaiter that can await on this notifier.

◆ operator()()

template<typename Result , typename... Args>
auto v1::notifier< Result(Args...)>::operator() ( Args const &... args) const
inlinenoexcept

Call the subscribed callbacks with the given arguments.

Note
This function is not reentrant.
Parameters
argsThe arguments to pass with the invocation of the callback

◆ post()

template<typename Result , typename... Args>
void v1::notifier< Result(Args...)>::post ( Args const &... args) const
inlinenoexcept

Post the subscribed callbacks on the current thread's event loop with the given arguments.

Note
This function is not reentrant.
Parameters
argsThe arguments to pass with the invocation of the callback

◆ post_on_main()

template<typename Result , typename... Args>
void v1::notifier< Result(Args...)>::post_on_main ( Args const &... args) const
inlinenoexcept

Post the subscribed callbacks on the main thread's event loop with the given arguments.

Note
This function is not reentrant.
Parameters
argsThe arguments to pass with the invocation of the callback

◆ subscribe()

template<typename Result , typename... Args>
token_type v1::notifier< Result(Args...)>::subscribe ( std::invocable< Args... > auto && callback)
inlinenoexcept

Add a callback to the notifier.

Ownership of the callback belongs with the caller of subscribe(). The caller will receive a token, a move-only RAII object that will unsubscribe the callback when the token is destroyed.

Parameters
callback_ptrA shared_ptr to a callback function.
Returns
A RAII object which when destroyed will unsubscribe the callback.

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