zed/crates/reqwest_client/examples/client.rs
Mikayla Maki 22ac178f9d
Some checks are pending
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
Restore HTTP client transition, but use reqwest everywhere (#19055)
Release Notes:

- N/A
2024-10-11 14:58:58 -07:00

41 lines
1.3 KiB
Rust

use std::time::Instant;
use futures::stream::FuturesUnordered;
use futures::AsyncReadExt as _;
use http_client::AsyncBody;
use http_client::HttpClient;
use reqwest_client::ReqwestClient;
use smol::stream::StreamExt;
fn main() {
let app = gpui::App::new();
app.run(|cx| {
cx.spawn(|cx| async move {
let client = ReqwestClient::new();
let start = Instant::now();
let requests = [
client.get("https://www.google.com/", AsyncBody::empty(), true),
client.get("https://zed.dev/", AsyncBody::empty(), true),
client.get("https://docs.rs/", AsyncBody::empty(), true),
];
let mut requests = requests.into_iter().collect::<FuturesUnordered<_>>();
while let Some(response) = requests.next().await {
let mut body = String::new();
response
.unwrap()
.into_body()
.read_to_string(&mut body)
.await
.unwrap();
println!("{}", &body.len());
}
println!("{:?}", start.elapsed());
cx.update(|cx| {
cx.quit();
})
.ok();
})
.detach();
})
}