SW Task Event Loop Framework v1.0.0
High-performance C++ asynchronous event loop framework with timer management and promise-based programming
|
Awaitable for executing work on background thread. More...
#include <Awaitable.h>
Public Member Functions | |
template<typename Func > | |
WorkAwaitable (std::shared_ptr< SLLooper > looper, Func &&func) | |
Construct WorkAwaitable with function. | |
bool | await_ready () const noexcept |
Check if result is ready (coroutine interface) | |
void | await_suspend (std::coroutine_handle<> handle) const noexcept |
Suspend coroutine and execute work on background thread. | |
auto | await_resume () const -> T |
Resume coroutine and return result. | |
std::shared_ptr< SLLooper > | getLooper () const |
Get the SLLooper instance. | |
std::function< T()> | getFunc () const |
Get the work function. | |
void | setResult (T result) const |
Set successful result (internal use) | |
void | setException (std::exception_ptr ex) const |
Set exception result (internal use) | |
Awaitable for executing work on background thread.
T | Return type of the background work function |
WorkAwaitable executes a function on a background thread and suspends the coroutine until the work completes. The result is then returned to the coroutine when it resumes.
Definition at line 43 of file Awaitable.h.
|
inline |
Construct WorkAwaitable with function.
Func | Function type (auto-deduced) |
looper | Shared pointer to SLLooper |
func | Function to execute on background thread |
Definition at line 59 of file Awaitable.h.
|
inlinenoexcept |
Check if result is ready (coroutine interface)
Definition at line 66 of file Awaitable.h.
|
inline |
Resume coroutine and return result.
std::exception | if work failed |
Definition at line 79 of file Awaitable.h.
|
noexcept |
Suspend coroutine and execute work on background thread.
handle | Coroutine handle for resumption |
Definition at line 258 of file SLLooper.cpp.
References SLLOOPER_DEBUG, SLLOOPER_ERROR, and SLLOOPER_ERROR_STREAM.
|
inline |
|
inline |
Get the SLLooper instance.
Definition at line 89 of file Awaitable.h.
|
inline |
Set exception result (internal use)
ex | Exception pointer from work function |
Definition at line 110 of file Awaitable.h.
|
inline |
Set successful result (internal use)
result | Result value from work function |
Definition at line 101 of file Awaitable.h.