Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> While asnyc/await (and callbacks and promises before) solves an efficiency problem via compiler magic and language extensions, it's not obvious whether it's necessarily the best solution to the problem.

The nice thing about Rust is that if kernel threads solve your problem, you can just use kernel threads. Some common reasons for using async, however, include:

1. Handling a larger number of connections than the kernel can support using threads.

2. Writing co-routines that operate over streams. This is sort of the in-process version of Unix CLI tools communicating by pipelines. For various reasons, it often seems to be much better handled in async frameworks.

3. Using networking libraries that happen to be async. This is actually fairly common in Rust, and it's arguable not a good reason to use async. On the other hand, Rust has tools for wrapping async code in a sync API, and several of the most popular async libraries do this.

Rust, however, does force you to choose between kernel threads and async coroutines. Rust does not support transparent green threads. This was an explicit design decision, largely driven by two goals:

- Rust lives extremely "close to the machine".

- Rust prefers to make the costs of operations explicitly visible.

Both of these concerns pushed heavily towards removing Rust's original green thread runtime support. However, these two concerns are very specific to languages like Rust that focus on making expensive things visible. Other languages which are more forgiving of runtime overhead would probably be better served by supporting transparent green threads.



Sure, rust is a low-level language, it needs absolute control over execution so it is very much validated in having an async keyword.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: