4 ms·
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 a
by pimeys 7y 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/executor/struct.ThreadPool.html https://docs.rs/futures-preview/0.3.0-alpha.17/futures/execu...
https://github.com/withoutboats/juliex https://github.com/withoutboats/juliex
And a web server to try out async/await on nightly:
https://github.com/rustasync/tide 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_util/compat/index.html https://docs.rs/futures-util-preview/0.3.0-alpha.17/futures_...
- jkarneges 7y agoFor 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/cb1ee686ef97bb05ebe04b5fc67536f4 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-part-1/ https://www.viget.com/articles/understanding-futures-in-rust...
- pimeys 7y agoHere's another example how to mix futures 0.1 and async/await together. https://github.com/pimeys/blocking_test/ https://github.com/pimeys/blocking_test/
- jadbox 7y agoThank 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
- steveklabnik 7y agoThere is an “async book” in the works, by the working group. You’re 100% right that good docs will be important here!
- baby 7y ago> watch out certain libraries using `tokio::spawn` , which will cause panics care to expand on that?
- pimeys 7y agotokio::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.