From ff76bdb4ab88ab8daaf2c87142b5aa299bbad5ec Mon Sep 17 00:00:00 2001 From: Peter Sonntag Date: Wed, 8 Jul 2020 21:07:34 +0200 Subject: [PATCH 1/3] 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 f81a483d2..e8f0d036a 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, From 0162ba4ec6aac64ae3e2344a7717d2e9062c3e95 Mon Sep 17 00:00:00 2001 From: tronta Date: Wed, 8 Jul 2020 21:16:20 +0200 Subject: [PATCH 2/3] Update spawn.rs shortens count down --- src/task/spawn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/task/spawn.rs b/src/task/spawn.rs index e8f0d036a..d34a39f27 100644 --- a/src/task/spawn.rs +++ b/src/task/spawn.rs @@ -40,7 +40,7 @@ use crate::task::{Builder, JoinHandle}; /// println!("Start"); /// task::spawn(clock()); /// -/// for i in (0..100).rev() { +/// for i in (0..=10).rev() { /// println!("Countdown {}", i); /// task::sleep(Duration::from_secs(2)).await; /// } From cdfdacd70bcc7ea7cd6236ed1b85cab33f728321 Mon Sep 17 00:00:00 2001 From: tronta Date: Wed, 8 Jul 2020 21:55:53 +0200 Subject: [PATCH 3/3] Update spawn.rs disables check because of errors with #[async_std::main] --- src/task/spawn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/task/spawn.rs b/src/task/spawn.rs index d34a39f27..857d3f398 100644 --- a/src/task/spawn.rs +++ b/src/task/spawn.rs @@ -24,7 +24,7 @@ use crate::task::{Builder, JoinHandle}; /// # }) /// ``` /// -/// ``` +/// ```ignore /// use async_std::task; /// use std::time::Duration; /// pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy