45 std::shared_ptr<SLLooper> mLooper;
46 std::function<T()> mFunc;
47 mutable std::optional<T> mResult;
48 mutable std::exception_ptr mException;
49 mutable bool mReady =
false;
58 template<
typename Func>
60 : mLooper(looper), mFunc(std::forward<Func>(func)) {}
72 void await_suspend(std::coroutine_handle<> handle)
const noexcept;
80 if (mException) std::rethrow_exception(mException);
81 if (mResult.has_value())
return std::move(mResult.value());
82 throw std::runtime_error(
"Work not completed");
89 std::shared_ptr<SLLooper>
getLooper()
const {
return mLooper; }
95 std::function<T()>
getFunc()
const {
return mFunc; }
133 std::shared_ptr<SLLooper> mLooper;
134 std::function<void()> mFunc;
135 mutable std::exception_ptr mException;
136 mutable bool mReady =
false;
145 template<
typename Func>
147 : mLooper(looper), mFunc(std::forward<Func>(func)) {}
159 void await_suspend(std::coroutine_handle<> handle)
const noexcept;
166 if (mException) std::rethrow_exception(mException);
167 if (!mReady)
throw std::runtime_error(
"Work not completed");
174 std::shared_ptr<SLLooper>
getLooper()
const {
return mLooper; }
180 std::function<void()>
getFunc()
const {
return mFunc; }
210 std::shared_ptr<SLLooper> mLooper;
212 mutable bool mReady =
false;
221 : mLooper(looper), mDelayMs(delayMs) {}
233 void await_suspend(std::coroutine_handle<> handle)
const noexcept;
250 std::shared_ptr<SLLooper>
getLooper()
const {
return mLooper; }
277 std::shared_ptr<SLLooper> mLooper;
278 std::function<T()> mFunc;
279 mutable std::optional<T> mResult;
280 mutable std::exception_ptr mException;
281 mutable bool mReady =
false;
290 template<
typename Func>
292 : mLooper(looper), mFunc(std::forward<Func>(func)) {}
304 void await_suspend(std::coroutine_handle<> handle)
const noexcept;
312 if (mException) std::rethrow_exception(mException);
313 if (mResult.has_value())
return std::move(mResult.value());
314 throw std::runtime_error(
"Post not completed");
321 std::function<T()>
getFunc()
const {
return mFunc; }
327 std::shared_ptr<SLLooper>
getLooper()
const {
return mLooper; }
365 std::shared_ptr<SLLooper> mLooper;
366 std::function<void()> mFunc;
367 mutable std::exception_ptr mException;
368 mutable bool mReady =
false;
377 template<
typename Func>
379 : mLooper(looper), mFunc(std::forward<Func>(func)) {}
391 void await_suspend(std::coroutine_handle<> handle)
const noexcept;
398 if (mException) std::rethrow_exception(mException);
405 std::function<void()>
getFunc()
const {
return mFunc; }
411 std::shared_ptr<SLLooper>
getLooper()
const {
return mLooper; }
Awaitable for delay operations.
void setReady() const
Mark delay as completed (internal use)
bool await_ready() const noexcept
Check if delay is ready (coroutine interface)
void await_suspend(std::coroutine_handle<> handle) const noexcept
Suspend coroutine and start timer.
int getDelayMs() const
Get delay duration.
void await_resume() const noexcept
Resume coroutine after delay (no return value)
DelayAwaitable(std::shared_ptr< SLLooper > looper, int delayMs)
Construct DelayAwaitable with delay duration.
std::shared_ptr< SLLooper > getLooper() const
Get the SLLooper instance.
std::shared_ptr< SLLooper > getLooper() const
Get the SLLooper instance.
PostAwaitable(std::shared_ptr< SLLooper > looper, Func &&func)
Construct PostAwaitable with void function.
std::function< void()> getFunc() const
Get the main thread function.
void setResult() const
Mark operation as completed (internal use)
void await_resume() const
Resume coroutine after void operation completion.
void setException(std::exception_ptr ex) const
Set exception result (internal use)
bool await_ready() const noexcept
Check if operation is ready (coroutine interface)
Awaitable for executing function on main thread.
void await_suspend(std::coroutine_handle<> handle) const noexcept
Suspend coroutine and post to main thread.
bool await_ready() const noexcept
Check if result is ready (coroutine interface)
std::function< T()> getFunc() const
Get the main thread function.
void setException(std::exception_ptr ex) const
Set exception result (internal use)
void setResult(T result) const
Set successful result (internal use)
PostAwaitable(std::shared_ptr< SLLooper > looper, Func &&func)
Construct PostAwaitable with function.
std::shared_ptr< SLLooper > getLooper() const
Get the SLLooper instance.
auto await_resume() const -> T
Resume coroutine and return result.
Central event loop coordinator providing asynchronous task execution and timer management.
std::shared_ptr< SLLooper > getLooper() const
Get the SLLooper instance.
bool await_ready() const noexcept
Check if work is ready (coroutine interface)
void await_resume() const
Resume coroutine after void work completion.
WorkAwaitable(std::shared_ptr< SLLooper > looper, Func &&func)
Construct WorkAwaitable with void function.
void setException(std::exception_ptr ex) const
Set exception result (internal use)
std::function< void()> getFunc() const
Get the work function.
void setResult() const
Mark work as completed (internal use)
Awaitable for executing work on background thread.
std::shared_ptr< SLLooper > getLooper() const
Get the SLLooper instance.
void setException(std::exception_ptr ex) const
Set exception result (internal use)
void await_suspend(std::coroutine_handle<> handle) const noexcept
Suspend coroutine and execute work on background thread.
void setResult(T result) const
Set successful result (internal use)
bool await_ready() const noexcept
Check if result is ready (coroutine interface)
auto await_resume() const -> T
Resume coroutine and return result.
WorkAwaitable(std::shared_ptr< SLLooper > looper, Func &&func)
Construct WorkAwaitable with function.
std::function< T()> getFunc() const
Get the work function.
Software Timer namespace containing all timer-related classes.