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