Using async
in Rust can lead to bad surprises. I recently came across
a particularly gnarly one, and I thought it was interesting enough to
share a little discussion. I think that we are too used to the burden
of separating async
from blocking being on the programmer, and
Rust can and should do better, and so can operating system APIs,
especially in subtle situations like the one I describe here.
Blocking Sockets and Async
In Defense of Async: Function Colors Are Rusty
Finally in 2019, Rust stabilized the async
feature, which supports
asynchronous operations in a way that doesn’t require multiple operating
system threads. This feature was so anticipated and hyped and in
demand that there was a website whose sole
purpose was to announce its stabilization.
async
was controversial from its inception; it’s still controversial
today; and in this post I am throwing my own 2 cents into this
controversy, in defense of the feature. I am only going to try to
counter one particular line of criticism here, and I don’t anticipate
I’ll cover all the nuance of it – this is a multifaceted issue, and
I have a day job. I am also going to assume for this
post that you have some understanding of how async
works, but if
you don’t, or just want a refresher I heartily recommend the Tokio
tutorial.