Crates.io | simple-concurrent-get |
lib.rs | simple-concurrent-get |
version | |
source | src |
created_at | 2024-11-18 07:13:17.936677 |
updated_at | 2024-11-25 10:34:55.076974 |
description | Simply make multiple concurrent HTTP GET requests |
homepage | https://github.com/ParkSnoopy/simple-concurrent-get |
repository | https://github.com/ParkSnoopy/simple-concurrent-get |
max_upload_size | |
id | 1451888 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Make multiple concurrent HTTP GET requests with ease.
concurrent_get
#[tokio::main]
async fn main() {
let request_urls = vec![
"https://example.com/1",
"https://example.com/2",
"https://example.com/3",
"https://example.com/4",
// ...
];
// for example: maximum 3 concurrent request
let request_results = simple_concurrent_get::concurrent_get(request_urls, 3);
let _: Vec<_> = request_results
.await
.map(|result| match result {
Ok(response) => {
let url = response.url().to_owned();
let bytes = futures_executor::block_on(async{ response.bytes().await }).unwrap();
println!("Successfully got '{}' with '{}' bytes of content", url, bytes.len())
},
Err(e) => eprintln!("{}", e),
})
.collect();
}
concurrent_get_foreach
#[tokio::main]
async fn main() {
let request_urls = vec![
"https://example.com/1",
"https://example.com/2",
"https://example.com/3",
"https://example.com/4",
// ...
];
// for example: maximum 3 concurrent request
let _: Vec<_> = simple_concurrent_get::concurrent_get_foreach(request_urls, 3,
|result| match result {
Ok(response) => {
let url = response.url().to_owned();
let bytes = futures_executor::block_on(async{ response.bytes().await }).unwrap();
println!("Successfully got '{}' with '{}' bytes of content", url, bytes.len())
},
Err(e) => eprintln!("{}", e),
}
)
.await
.collect();
}