[Pitch] Task Cancellation Shields

Well, sure… you can write this, it’s because this API composes with all other existing ones; Is it pretty weird and you likely shouldn’t? But yeah, you can.

Again, the goal never is to make it absolutely impossible to write weird things. You can abuse a lot of APIs. In the same way, you can write while true { await Task.yield() } which is a horrible idea, but we’re not going to stop you from doing that.

No, the fundamental building block cannot be limited to creating tasks. This specifically breaks ordering, and is inefficient. For something to be fundamental you need to be able to construct other things on top of it – as is the case with the proposed APIs, and would not be with a new task initializer.

In addition to that, you would not have the ability to create such section in a defer without creating new tasks, and incuring scheduling (unless again specifically using Task.immediate…). This really would complicate the model, rather than simplify it.

I’m also opposed to this idea on sheer API surface and discovery grounds; It would mean around ~6 task initializers, ~8 task group child apis, and no way to spell this in an async let child task at all (!).

I’m happy to add this to the alternatives considered section though, with this argumentation why it’s not the right way here.

5 Likes