From ff76bdb4ab88ab8daaf2c87142b5aa299bbad5ec Mon Sep 17 00:00:00 2001 From: Peter Sonntag Date: Wed, 8 Jul 2020 21:07:34 +0200 Subject: [PATCH] Adds example to async_std::task::spawn --- src/task/spawn.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/task/spawn.rs b/src/task/spawn.rs index f81a483d..e8f0d036 100644 --- a/src/task/spawn.rs +++ b/src/task/spawn.rs @@ -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(future: F) -> JoinHandle where F: Future + Send + 'static,