mirror of
https://github.com/Noratrieb/ice-104649.git
synced 2026-01-14 20:45:01 +01:00
no async
This commit is contained in:
parent
206a6628ea
commit
9d73254291
1 changed files with 12 additions and 27 deletions
39
src/main.rs
39
src/main.rs
|
|
@ -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;
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue