Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.48 KB | None | 0 0
  1. use futures::future;
  2. use std::error::Error;
  3. use tokio::task::JoinHandle;
  4.  
  5. #[tokio::main]
  6. async fn main() -> Result<(), Box<dyn Error>> {
  7.   tokio::spawn(async move {
  8.     let mut handles: Vec<JoinHandle<()>> = Vec::new();
  9.  
  10.     for a in 1..5 {
  11.       let handle = tokio::spawn(async move {
  12.         println!("Got {}", a);
  13.       });
  14.  
  15.       handles.push(handle);
  16.     }
  17.  
  18.     future::join_all(handles).await;
  19.   })
  20.   .await
  21.   .unwrap();
  22.  
  23.   println!("done!");
  24.  
  25.   Ok(())
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement