This commit is contained in:
nora 2022-11-20 20:18:57 +01:00
commit e8ea766ff0
No known key found for this signature in database
4 changed files with 1290 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1233
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

12
Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "ice-104649"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11", features = ["json", "brotli", "gzip", "native-tls", "deflate"] }
tokio = { version = "1", features = ["full"] }
futures = "0.3.25"
snafu = { version = "0.7.3", features = ["rust_1_61", "backtraces-impl-std"] }

44
src/main.rs Normal file
View file

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