i also studied the cancellable coroutines implemented by folly and C++/WinRT. both of them implement the cancellable coroutine. i believe there should be an elegant way to implement a similar cancellable coroutine in Seastar. but i am afraid it won't be trivial. some rough ideas:
1. we will have a cancellable token which is populated to the the coroutines created by their parent coroutine. the cancellable token should be stored in `task` (or `cancellable_task` ?)
2. the internal state is shared by the outer most caller and all the coroutines on the leafs. assuming we need to cancel the subcoroutines created by calls like `when_all()`, which creates multiple coroutines and run them in parallel.
3. the source of the cancellation need to explicitly created by the caller of the cancellable coroutine.
3. ideally, the cancel operation can be optionally populated all the way down to the reactor backend. please note, io_uring can cancel a previously submitted request. so all low-level ops will need to have their own cancellable variants.
4. a new coroutine type which is different from the existing one will be created. probably we don't need to create a parallel series of coroutine types, we could use CPO to let the coroutines to opt-in, so they can customize 1) how the token is passed down, 2) how the cancellation is performed. sometimes, if we can just close an fd or, in io_uring, submit a cancellation request . so a callback is more capable in this case.
i am not sure how await_resume is able to access a variable stored in the coroutine frame. do you mean storing it in the `promise_type`? if that's the case, it's quite similar to what i suggest above: to store it in the task. but i prefer storing the token.
anyway, IMHO, this approach is inherently limited. as i think a more capable solution is to allow us to cancel a coroutine even when it is suspended.
Thank you!