async/await

06 Dec 2019

Today Iā€™m releasing version 0.11.0 of capnproto-rust, with support for async/await! The updated RPC system works with any futures-0.3-enabled executor (e.g. tokio, async-std) ā€“ you just need to provide it with objects that implement the futures::io::AsyncRead and futures::io::AsyncWrite traits.

The stabilization of std::future::Future allowed me to eliminate an annoying optional dependecy on futures-0.1 in the base capnp crate, and in general the update allowed me to delete a lot of code.

In my experience, async/await can vastly simplify concurrent programming, especially in the case where you have a single-threaded event loop and you want to share mutable data among multiple tasks.

Probably the hardest part of this update was wrapping my head around Pin<T>. My biggest takeaway message on that topic is: if you get into trouble, try wrapping your object with Box::pin(). Curiously, doing so will give you an object that is Unpin ā€“ which is often exactly what you need!

-- posted by dwrensha

capnproto-rust on github
more posts