C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Cooperative Cancellation of Coroutines

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Sun, 9 Aug 2026 19:35:53 +0300
On Sun, 9 Aug 2026 at 10:08, Lénárd Szolnoki via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
>
>
> On 8 August 2026 08:46:09 CEST, Ville Voutilainen via Std-Proposals <std-proposals_at_[hidden]> wrote:
> >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.
>
> Does that do any (possibly async) work besides destroying the coroutine?

It invokes the stop continuations, yes.

Received on 2026-08-09 16:36:11