mirror of
https://github.com/Noratrieb/ice-104649.git
synced 2026-01-14 12:35:02 +01:00
init
This commit is contained in:
commit
e8ea766ff0
4 changed files with 1290 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/target
|
||||
1233
Cargo.lock
generated
Normal file
1233
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal 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
44
src/main.rs
Normal 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>;
|
||||
Loading…
Add table
Add a link
Reference in a new issue