mirror of
https://github.com/async-rs/async-std.git
synced 2025-10-21 01:26:35 +00:00
Adds example to async_std::task::spawn
This commit is contained in:
parent
c82b1efb69
commit
ff76bdb4ab
1 changed files with 24 additions and 0 deletions
|
@ -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>
|
pub fn spawn<F, T>(future: F) -> JoinHandle<T>
|
||||||
where
|
where
|
||||||
F: Future<Output = T> + Send + 'static,
|
F: Future<Output = T> + Send + 'static,
|
||||||
|
|
Loading…
Reference in a new issue