Created
November 22, 2024 20:58
-
-
Save danielhe4rt/59ded56be8311053fc083072bd75d7f0 to your computer and use it in GitHub Desktop.
rust stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::future::Future; | |
use tokio::task::JoinSet; | |
#[tokio::main] | |
async fn main() { | |
println!("Hello, world!"); | |
// store multiple threads pool | |
let mut set = JoinSet::new(); | |
for _ in 0..10 { | |
set.spawn(cool_function()); | |
} | |
while let Some(res) = set.join_next().await { | |
res.unwrap() | |
} | |
println!("All done"); | |
} | |
async fn cool_function() -> impl Future<Output=()> + Sized { | |
let res = reqwest::get("https://ifconfig.me").await; | |
match res { | |
Ok(mut response) => { | |
match response.text().await { | |
Ok(text) => { | |
println!("Response: {}", text); | |
}, | |
Err(e) => { | |
println!("Error: {}", e); | |
} | |
} | |
}, | |
Err(e) => { | |
println!("Error: {}", e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment