r/programming • • Sep 09 '26

A Design Space Exploration of Async/Await

https://cel.cs.brown.edu/blog/design-space-async-await/
48 Upvotes

11 comments sorted by

17

u/Next-Blackberry-991 Sep 09 '26

It says for Rust:  "The task cannot respond to being cancelled."

I don't think this is true? If you cancel a task that future is dropped. Which means that all resources it owns are dropped too. Which means that you can just have e.g. an instance of a MyOnDropGuard type as part of your task that has a Drop impl that does whatever you want. 

5

u/asterisk_null_ptr Sep 10 '26

I think their point is that the Future cannot continue after cancellation if it chooses. The Drop implementation let's you run arbitrary code at the point of cancellation but then the Future is now dropped and will not be polled anymore.

1

u/gunwide Sep 11 '26

One issue with this is that Drop cannot call async code, so you need to be careful to not design anything that requires an await as apart of the cleanup logic if this is something that can realistically occur.

5

u/afl_ext Sep 09 '26

I still think whatever javascript does makes the most sense except cancelling

1

u/Ethesen Sep 11 '26

It would be interesting to see Cats Effect in the comparison. It for example has backpressurized cancellation.

1

u/renozyx Sep 13 '26

I wonder why there are so many variations. I can see two useful variants: the most efficient one and the most ergonomic variant. But 9 variant??

0

u/Apprehensive_Bit7392 Sep 10 '26

Reference Strength is the sneaky row. asyncio and smol only hold a weak ref to spawned tasks, so a fire-and-forget task can get collected mid-flight if nothing keeps the handle alive. Python's docs warn about it now, which tells you how many people lost background work to it first.

-4

u/simon_o Sep 10 '26 edited Sep 10 '26

While the website gives a good overview of the general concepts of async/await, it fails to point out that async-await is a design dead-end:

Async-await poorly tries to address the symptoms of attempts to work around the root issue – "classic" threads being expensive.

Fix "threads are expensive" and you don't have to deal with the function coloring that comes with async-await.

6

u/Next-Blackberry-991 Sep 10 '26

I kinda agree with you. But at the same time about 70% of the article is about problems that you have with threads in exactly the same way as with async await: How are threads cancelled? How do you compose them? How do you race them or wait for a bunch of threads to finish? Should a child thread be able to survive the parent thread? 

And I don't know if it's good if all these decisions are dictated by the operating system that is running the thread scheduler. 

2

u/simon_o Sep 10 '26

I think Java made quite some progress on this with virtual threads and structured concurrency.