C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Cooperative Cancellation of Coroutines

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Sat, 8 Aug 2026 09:46:09 +0300
On Sat, 8 Aug 2026 at 09:43, Yexuan Xiao via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> In C++, the most common use of coroutines is not generators, but asynchrony, which is the primary reason they were introduced into C++. However, generators are indeed important as well, and the new API is useful for nested generators that may throw exceptions. std::generator in C++23 supports nesting, so exceptions thrown by an inner generator are caught and rethrown by each outer generator. If the generator nesting is very deep, this overhead can be significant. However, this is uncommon in real world code, because generators typically do not have complex nesting relationships. Therefore, this improvement is mainly useful for asynchronous code, which may be nested deeply.

If you co_await a C++26 sender, you get a cancellable coroutine, and
you can cancel a C++26 std::task.

The coroutines in Capy (https://github.com/cppalliance/capy) are also
cancellable.

Received on 2026-08-08 06:46:26