Defer the current coroutine to a different dispatcher context.
More...
#include <asyncpp/defer.h>
|
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.
|
|
|
TDispatcher * | target_dispatcher |
| The new dispatcher to resume execution on.
|
|
template<Dispatcher TDispatcher>
struct asyncpp::defer< TDispatcher >
Defer the current coroutine to a different dispatcher context.
- Template Parameters
-
TDispatcher | Type 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.
◆ defer() [1/2]
template<Dispatcher TDispatcher>
constexpr asyncpp::defer< TDispatcher >::defer |
( |
TDispatcher * | target | ) |
|
|
inlineexplicitconstexprnoexcept |
Construct with a pointer to a dispatcher.
- Parameters
-
target | The 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
-
target | The dispatcher to resume on. |
◆ await_ready()
template<Dispatcher TDispatcher>
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
-
The documentation for this struct was generated from the following file: