async
/ await
功能即将推出,但仍有许多库仍在使用Futures 0.1。我们如何在两者之间转换?
Convert an async future to 0.1 future涵盖了将异步Future转换为0.1 Future。
How do I erase the type of future in the new future API?讨论了一个{0.1}函数,该函数调用0.1 Future并获取结果,但是我可以导入的async
宏在哪里?看来它不再编译。
await!()
答案 0 :(得分:1)
使用Future01CompatExt
特性:
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-preview", version = "0.3.0-alpha.19", features = ["compat"] }
futures01 = { package = "futures", version = "0.1.29" }