This commit is contained in:
nora 2022-11-20 20:23:42 +01:00
parent 206a6628ea
commit 9d73254291
No known key found for this signature in database

View file

@ -1,20 +1,11 @@
use futures::{stream, StreamExt};
use std::time::{Duration, Instant};
const REQUEST_COUNT: usize = 10;
const CONCURRENT_REQUESTS: usize = 1_000;
#[tokio::main]
async fn main() -> Result<(), Error> {
let client = reqwest::Client::builder()
.build()
.unwrap();
let urls = vec![String::from("http://example.com")];
fn main() {
let client = reqwest::Client::builder().build().unwrap();
// Concurrent Requests
let bodies = stream::iter(urls)
.map(|url| {
let bodies = stream::iter([])
.map(|url: String| {
let req = client.get(&url);
tokio::spawn(async move {
let resp = req.send().await.unwrap();
@ -22,19 +13,13 @@ async fn main() -> Result<(), Error> {
Result::Ok((url, text))
})
})
.buffer_unordered(CONCURRENT_REQUESTS);
.buffer_unordered(0);
bodies
.for_each(|b| async {
bodies.for_each(|b| async {
match b {
Ok(Ok((url, b))) => {}
Err(e) => {}
Ok(Err(e)) => {}
}
})
.await;
Ok(())
});
}
struct Error;