Learning asynchronous programming in Rust

I recently found myself needing to write a dynamic reverse HTTP/websocket proxy. After some prototyping it is now time to write something real. To prepare myself for that, I devoted today’s Red Hat Day of Learning to another aspect of Rust: asynchronous programming, and learning about tokio. There is really no getting around tokio in the Rust world of networking.

I started with the small book “Asynchronous Programming in Rust”. Honestly I found this a bit hard to follow, as it quickly dives into a lot of technical details, which I don’t have yet. But I understand the basics now: futures, async/.await, and an overview about available runtimes. As JavaScript developer I’m of course very familiar with async programming in general (a JS Promise is more or less the same as a Rust Future), but due to Rust’s much stricter typing and borrowing rules and multi-threading capabilities there are a lot of extra details to consider.

Moving on to tokio, I found a nice blog post from Jakub Barszczewski that explains the basics of tokio on a simple web service example. That was very well written, easy to follow and understand. It only took an hour or so to work through, including copious excursions to API docs.

Armed with that, I am now working through the official tokio tutorial. The first chapters were now rather familiar to me, but for a tutorial it’s always a good idea to start with the concepts. This is also very well structured and comprehensible.

I keep the code evolution from the tutorials in my learn-rust.git. However, there is literally nothing exciting in there 😀.