✨ Add proxy capability to context & add cancellation support #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a proxy system to the async context, introduces an unsafe cancellation routine for contexts, refactors a number of coroutine helpers and updates the test suite accordingly. The changes also include new benchmarks, build system tweaks, and minor clean‑ups.
Proxy provides a means for a coroutine to use its context to supervise other async operations without losing control over being the active coroutine.
Key Functional Changes
context::borrow_proxy()now returns a proxy context that shares the same stack space as its parent but has its own active coroutine handle. The proxy owns aproxy_infostruct that tracks the original “origin” and the parent. The proxy is created via a private constructorcontext(proxy_tag, context&).m_proxymember was ascheduler_t; it is now aproxy_statevariant (`proxy_infocontext::unsafe_cancel()walks the coroutine chain starting fromm_active_handleand destroys every coroutine up to the top‑level one. The stack is reset but the public future object that was bound to this context is not marked cancelled – hence “unsafe”.memory_used(),capacity(), andmemory_remaining()were updated to use the new layout.state()method now returns ablocked_by(defaulting tonothing) and the transition logic uses the proxy’s scheduler.futurenow stores its state in a variantfuture_state<T>(`handlefuture::cancel()destroys the coroutine and marks its state ascancelled_state. Helperoperation_cancelledexception is thrown when awaiting a cancelled future.promise::get_return_object()now creates the future from the promise’s coroutine handle and records the frame size.future<void>has its own awaiter that throws if the future was cancelled or had an exception.context(scheduler_t const&, usize)now initializes the proxy field. The oldm_schedulermember is removed; scheduler is stored inproxy_state.borrow_proxy()is deleted for temporaries (context&&) to avoid dangling references.Test Additions
unsafe_cancel()correctly destroys all coroutines and resets the stack.Benchmark Additions
benchmarksdirectory with the original benchmark file (benchmark.cpp) moved frombenchmark.Build System & Packaging
CMakeLists.txtnow:benchmarks/*to the source list.async_benchmarkexecutable only when not cross‑compiling.conanfile.pyboost-ext-ut,benchmark) when building for non‑baremetal OSes.