zed/crates/reqwest_client/examples/client.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.3 KiB
Rust
Raw Permalink Normal View History

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();
})
}