The async
/await
feature is coming soon, but there are a lot of libraries still using futures 0.1. How do we convert between the two?
Conver
Use the Future01CompatExt
trait:
use futures01::future as future01;
use futures03::compat::Future01CompatExt;
fn make_future_01() -> impl future01::Future<Item = i32, Error = ()> {
future01::ok(2)
}
async fn example_03_uses_01() -> Result<i32, ()> {
let v = make_future_01().compat().await?;
Ok(v)
}
[dependencies]
futures03 = { package = "futures", version = "0.3", features = ["compat"] }
futures01 = { package = "futures", version = "0.1" }