Move "async move" a few characters to the left in cx.spawn() (#26758)

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
This commit is contained in:
Mikayla Maki 2025-03-18 19:09:02 -07:00 committed by GitHub
parent 7f2e3fb5bd
commit 1aefa5178b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
256 changed files with 3110 additions and 3200 deletions

View file

@ -151,14 +151,12 @@ impl Workspace {
})
});
if toast.autohide {
cx.spawn(|workspace, mut cx| async move {
cx.spawn(async move |workspace, cx| {
cx.background_executor()
.timer(Duration::from_millis(5000))
.await;
workspace
.update(&mut cx, |workspace, cx| {
workspace.dismiss_toast(&toast.id, cx)
})
.update(cx, |workspace, cx| workspace.dismiss_toast(&toast.id, cx))
.ok();
})
.detach();
@ -213,9 +211,9 @@ impl LanguageServerPrompt {
}
}
async fn select_option(this: Entity<Self>, ix: usize, mut cx: AsyncWindowContext) {
async fn select_option(this: Entity<Self>, ix: usize, cx: &mut AsyncWindowContext) {
util::maybe!(async move {
let potential_future = this.update(&mut cx, |this, _| {
let potential_future = this.update(cx, |this, _| {
this.request.take().map(|request| request.respond(ix))
});
@ -224,7 +222,7 @@ impl LanguageServerPrompt {
.await
.ok_or_else(|| anyhow::anyhow!("Stream already closed"))?;
this.update(&mut cx, |_, cx| cx.emit(DismissEvent))?;
this.update(cx, |_, cx| cx.emit(DismissEvent))?;
anyhow::Ok(())
})
@ -295,7 +293,7 @@ impl Render for LanguageServerPrompt {
.on_click(move |_, window, cx| {
let this_handle = this_handle.clone();
window
.spawn(cx, |cx| async move {
.spawn(cx, async move |cx| {
LanguageServerPrompt::select_option(this_handle, ix, cx)
.await
})
@ -846,10 +844,7 @@ where
{
fn detach_and_notify_err(self, window: &mut Window, cx: &mut App) {
window
.spawn(
cx,
|mut cx| async move { self.await.notify_async_err(&mut cx) },
)
.spawn(cx, async move |mut cx| self.await.notify_async_err(&mut cx))
.detach();
}
}
@ -884,7 +879,7 @@ where
f: impl FnOnce(&anyhow::Error, &mut Window, &mut App) -> Option<String> + 'static,
) -> Task<Option<R>> {
let msg = msg.to_owned();
window.spawn(cx, |mut cx| async move {
window.spawn(cx, async move |cx| {
let result = self.await;
if let Err(err) = result.as_ref() {
log::error!("{err:?}");