Hacker News new | ask | show | jobs
by pimeys 2538 days ago
std::future is stable. Async/await in about 12 weeks. Been writing loads of code, trying out the new futures and especially the possibility to use &self in an async context is a huge benefit.

Beware though to use an executor that can drive the new futures and watch out certain libraries using `tokio::spawn` , which will cause panics.

Some executors for the new futures:

https://docs.rs/futures-preview/0.3.0-alpha.17/futures/execu...

https://github.com/withoutboats/juliex

And a web server to try out async/await on nightly:

https://github.com/rustasync/tide

Compatibility layer from 0.1 to 0.3 and back is in futures-util-preview if compiled with the feature flag `compat`.

https://docs.rs/futures-util-preview/0.3.0-alpha.17/futures_...

2 comments

For anyone wanting to understand how to implement a basic engine for std::future from scratch, I mashed some code until it worked: https://gist.github.com/jkarneges/cb1ee686ef97bb05ebe04b5fc6...

It's based mostly on this article, which predates std::future: https://www.viget.com/articles/understanding-futures-in-rust...

Thank you. We really need more examples... and hopefully a full guide to futures/async. As someone currently in the outskirts of the Rust community, it's really hard to 'peer inside' what's happening and how to use it in practical applications. It's a matter of time, but it's just so exciting xD
There is an “async book” in the works, by the working group. You’re 100% right that good docs will be important here!
Here's another example how to mix futures 0.1 and async/await together.

https://github.com/pimeys/blocking_test/

> watch out certain libraries using `tokio::spawn` , which will cause panics

care to expand on that?

tokio::spawn needs to be run from the context of tokio's executor. If you use some other executor, such as juliex, it will panic.

This is hopefully solved by the Runtime crate and the crates using it will use a more generic version.