morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
coroutine.hpp File Reference

Coroutines on core::async::Task: awaiting a Completion, starting a detached flow on a morph executor, and waiting on a timer. More...

#include <atomic>
#include <chrono>
#include <core/async/Awaitable.hpp>
#include <core/async/Cancellation.hpp>
#include <core/async/ExecutorContext.hpp>
#include <core/async/IExecutor.hpp>
#include <core/async/ParkedWork.hpp>
#include <core/async/StopToken.hpp>
#include <core/async/Task.hpp>
#include <coroutine>
#include <cstdint>
#include <exception>
#include <memory>
#include <optional>
#include <utility>
#include "completion.hpp"
#include "detail/completion_awaiter.hpp"
#include "detail/task_handler.hpp"
#include "executor.hpp"
#include "logger.hpp"
#include "timeout_scheduler.hpp"

Go to the source code of this file.

Classes

class  morph::async::DelayAwaiter
 The awaiter delay() returns: suspends until a TimeoutScheduler entry fires, or until a stop withdraws it. More...

Functions

void morph::async::spawn (::morph::exec::IExecutor &executor, ::core::async::Task< void > task)
 Starts task detached, with every resumption – its first step included – posted to executor.
DelayAwaiter morph::async::delay (detail::TimeoutScheduler &scheduler, std::chrono::milliseconds duration)
 Suspends the awaiting coroutine for at least duration.

Detailed Description

Coroutines on core::async::Task: awaiting a Completion, starting a detached flow on a morph executor, and waiting on a timer.

Completion<T>::operator co_await itself lives in completion.hpp, so a completion is awaitable wherever it is visible; this header adds spawn and delay, and brings in what drives a Task-returning model handler. Specified in docs/spec/core/coroutines.md.

Definition in file coroutine.hpp.

Function Documentation

◆ spawn()

void morph::async::spawn ( ::morph::exec::IExecutor & executor,
::core::async::Task< void > task )
inline

Starts task detached, with every resumption – its first step included – posted to executor.

The entry point from code that is not itself a coroutine: with a QtExecutor, a GUI flow written as a coroutine runs every step on the GUI thread. Awaits inside task resume on executor, whichever thread the awaited operation completed on. An exception task lets escape is logged through morph::log and swallowed. Its stop token is never stopped.

Parameters
executorWhere the task runs; must outlive it.
taskThe task to run.

Definition at line 125 of file coroutine.hpp.

◆ delay()

DelayAwaiter morph::async::delay ( detail::TimeoutScheduler & scheduler,
std::chrono::milliseconds duration )
inlinenodiscard

Suspends the awaiting coroutine for at least duration.

co_await morph::async::delay(scheduler, 50ms). Stop-aware; see DelayAwaiter.

Parameters
schedulerThe scheduler whose entry times the wait; must outlive it.
durationHow long to wait at least.
Returns
The awaiter.

Definition at line 278 of file coroutine.hpp.