boost::capy::ExecutionContext
Requires a type to expose a noexcept get_executor() bound to its own resources.
Synopsis
template<class X>
concept ExecutionContext = std::derived_from<X, execution_context> &&
requires(X& x) {
typename X::executor_type;
requires Executor<typename X::executor_type>;
{ x.get_executor() } noexcept ‐> std::same_as<typename X::executor_type>;
};
Description
An execution context owns the resources (threads, event loops, completion ports) needed to run coroutine continuations. It serves as the factory for executors, which are lightweight handles used to submit work. Multiple executors may reference the same context.
Syntactic Requirements
-
Xmust be publicly derived fromexecution_context. -
X::executor_typemust be a type satisfyingExecutor. -
x.get_executor()must returnX::executor_typeand benoexcept.
Semantic Requirements
The execution context owns the execution environment:
-
Work submitted via any executor from this context runs on resources owned by the context.
-
The context remains valid while any executor referencing it exists and may be used.
-
Destroying the context discards work submitted via associated executors that has not started running, destroying the coroutines it would have resumed.
Conforming Signatures
class X : public capy::execution_context
{
public:
using executor_type = capy::executor_ref; // any type satisfying Executor
executor_type get_executor() noexcept;
};
static_assert( capy::ExecutionContext<X> );
Example
post takes a continuation&, which no closure converts to; ordinary callers reach it indirectly through run_async or similar combinators:
template<capy::ExecutionContext Ctx>
void spawn_work( Ctx& ctx, capy::task<> work )
{
auto ex = ctx.get_executor();
capy::run_async(ex)(std::move(work)); // schedules work; runs on ctx
}
See Also
Created with MrDocs