Closed
Description
Similar to #309 we should add a method to Future
that delays execution for a Duration
. This method should be marked as "unstable".
This is useful in some cases where you want to define a Future
that has a delay, rather than combining task::sleep
with an async block and another future.
Examples
use async_std::future;
let a = future::ready(1).delay(Duration::from_millis(200));
let b = future::ready(2).delay(Duration::from_millis(100));
let c = future::ready(3).delay(Duration::from_millis(300));
dbg!(future::join!(a, b, c).await);
This is simlilar to this, but less nice to write:
let a = async {
task::sleep(Duration::from_millis(200).await;
future::ready(1).await
};
let b = async {
task::sleep(Duration::from_millis(100).await;
future::ready(2).await
};
let c = async {
task::sleep(Duration::from_millis(300).await;
future::ready(3).await
};
dbg!(future::join!(a, b, c).await);