get_a_thousand_status_codes/src/main.rs

18 lines
626 B
Rust
Raw Permalink Normal View History

2020-08-17 10:33:48 +00:00
#[tokio::main]
async fn main() {
let mut handles = Vec::with_capacity(1000);
2020-08-17 12:19:16 +00:00
for url in include_str!("../test-urls.txt").split("\n") {
handles.push(tokio::spawn(async move {
match reqwest::ClientBuilder::new().user_agent("Test/contact: admin@cryto.net").build().unwrap().get(url).send().await.and_then(|resp| {
2020-08-17 10:33:48 +00:00
Ok(resp.status())
}) {
2020-08-17 12:19:16 +00:00
Ok(status) => println!("{}, {}", status, chrono::Utc::now()),
2020-08-17 10:33:48 +00:00
Err(_) => eprintln!("Something went wrong here"),
};
}));
}
for handle in handles {
handle.await;
}
}