Skip to content

Instantly share code, notes, and snippets.

@danielhe4rt
Created November 22, 2024 20:58
Show Gist options
  • Save danielhe4rt/59ded56be8311053fc083072bd75d7f0 to your computer and use it in GitHub Desktop.
Save danielhe4rt/59ded56be8311053fc083072bd75d7f0 to your computer and use it in GitHub Desktop.
rust stuff
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