2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-10-20 17:16:35 +00:00

Adds example to async_std::task::spawn

This commit is contained in:
Peter Sonntag 2020-07-08 21:07:34 +02:00
parent c82b1efb69
commit ff76bdb4ab

View file

@ -23,6 +23,30 @@ use crate::task::{Builder, JoinHandle};
/// #
/// # })
/// ```
///
/// ```
/// 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..100).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,