8 个版本
0.1.7 | 2019 年 4 月 17 日 |
---|---|
0.1.6 | 2019 年 4 月 17 日 |
0.1.5 | 2018 年 12 月 31 日 |
#1252 in 异步
每月 32 次下载
11KB
143 行
back-to-the-future
std
和 futures
兼容性
此 crate 实现了两种不同未来类型的适配器:std::future::Future
和 futures::Future
。您可以无缝地将一个转换为另一个。目标是能够使用新的 async/await 语法与现有的 futures::Future
基础设施,例如 tokio。
请注意,许多使用的功能仍然是不稳定的,并且只能在带有功能门控的 nightly 上使用。
简单示例
#![feature(async_await)]
#![feature(await_macro)]
#![feature(futures_api)]
use std::time::{Duration, Instant};
use tokio::timer::Delay;
use back_to_the_future::{futures_await, BoxIntoFutures};
fn main() {
let f = async {
// Await an old futures::Future using the futures_await! macro.
// This macro wraps the future in an adapter behind the scenes.
futures_await!(Delay::new(Instant::now() + Duration::new(0, 10))).unwrap();
Ok(())
};
// Convert the std::future::Future into a futures::Future so that tokio::run can use it.
tokio::run(f.box_into_futures());
}
依赖项
~53KB