mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-08 01:16:41 +00:00
Merge cdfdacd70b
into 96f564672a
This commit is contained in:
commit
62f214fade
1 changed files with 24 additions and 0 deletions
|
@ -23,6 +23,30 @@ use crate::task::{Builder, JoinHandle};
|
|||
/// #
|
||||
/// # })
|
||||
/// ```
|
||||
///
|
||||
/// ```ignore
|
||||
/// use async_std::task;
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// async fn clock() {
|
||||
/// loop {
|
||||
/// task::sleep(Duration::from_secs(1)).await;
|
||||
/// println!("Tick");
|
||||
/// }
|
||||
///}
|
||||
///
|
||||
/// #[async_std::main]
|
||||
/// async fn main() {
|
||||
/// println!("Start");
|
||||
/// task::spawn(clock());
|
||||
///
|
||||
/// for i in (0..=10).rev() {
|
||||
/// println!("Countdown {}", i);
|
||||
/// task::sleep(Duration::from_secs(2)).await;
|
||||
/// }
|
||||
/// println!("End");
|
||||
///}
|
||||
/// ```
|
||||
pub fn spawn<F, T>(future: F) -> JoinHandle<T>
|
||||
where
|
||||
F: Future<Output = T> + Send + 'static,
|
||||
|
|
Loading…
Reference in a new issue