
This is the core change: https://github.com/zed-industries/zed/pull/26758/files#diff-044302c0d57147af17e68a0009fee3e8dcdfb4f32c27a915e70cfa80e987f765R1052 TODO: - [x] Use AsyncFn instead of Fn() -> Future in GPUI spawn methods - [x] Implement it in the whole app - [x] Implement it in the debugger - [x] Glance at the RPC crate, and see if those box future methods can be switched over. Answer: It can't directly, as you can't make an AsyncFn* into a trait object. There's ways around that, but they're all more complex than just keeping the code as is. - [ ] Fix platform specific code Release Notes: - N/A
41 lines
1.3 KiB
Rust
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::Application::new();
|
|
app.run(|cx| {
|
|
cx.spawn(async move |cx| {
|
|
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();
|
|
})
|
|
}
|