Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
asyncpp::defer< TDispatcher > Struct Template Reference

Defer the current coroutine to a different dispatcher context. More...

#include <asyncpp/defer.h>

Public Member Functions

constexpr defer (TDispatcher *target) noexcept
 Construct with a pointer to a dispatcher.
 
constexpr defer (TDispatcher &target) noexcept
 Construct with a reference to a dispatcher.
 
constexpr bool await_ready () const noexcept
 Check if await should suspend.
 
void await_suspend (coroutine_handle<> hndl) const noexcept(noexcept(target_dispatcher->push(std::declval< std::function< void()> >())))
 Suspend the current coroutine and schedule resumption on the specified dispatcher.
 
constexpr void await_resume () const noexcept
 Called on resumption.
 

Public Attributes

TDispatcher * target_dispatcher
 The new dispatcher to resume execution on.
 

Detailed Description

template<Dispatcher TDispatcher>
struct asyncpp::defer< TDispatcher >

Defer the current coroutine to a different dispatcher context.

Template Parameters
TDispatcherType of the target dispatcher. Needs to provide a public "push" method.

This stops executions on the current dispatcher and reschedules the function on the provided dispatcher. It can be used if a function needs to run within a certain thread (e.g. libuv I/O) or to give a different task the chance to get work done. Does nothing if the dispatcher is nullptr.

Constructor & Destructor Documentation

◆ defer() [1/2]

template<Dispatcher TDispatcher>
constexpr asyncpp::defer< TDispatcher >::defer ( TDispatcher * target)
inlineexplicitconstexprnoexcept

Construct with a pointer to a dispatcher.

Parameters
targetThe dispatcher to resume on.
Note
If target is nullptr the defer is a noop and does not suspend.

◆ defer() [2/2]

template<Dispatcher TDispatcher>
constexpr asyncpp::defer< TDispatcher >::defer ( TDispatcher & target)
inlineexplicitconstexprnoexcept

Construct with a reference to a dispatcher.

Parameters
targetThe dispatcher to resume on.

Member Function Documentation

◆ await_ready()

template<Dispatcher TDispatcher>
constexpr bool asyncpp::defer< TDispatcher >::await_ready ( ) const
inlineconstexprnoexcept

Check if await should suspend.

Returns
true if a dispatcher was set.

◆ await_suspend()

template<Dispatcher TDispatcher>
void asyncpp::defer< TDispatcher >::await_suspend ( coroutine_handle<> hndl) const
inlinenoexcept

Suspend the current coroutine and schedule resumption on the specified dispatcher.

Parameters
hThe current coroutine

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