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:
parent
7f2e3fb5bd
commit
1aefa5178b
256 changed files with 3110 additions and 3200 deletions
|
@ -305,21 +305,20 @@ impl ExtensionStore {
|
|||
reload_future = Some(this.reload(None, cx));
|
||||
}
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
if let Some(future) = reload_future {
|
||||
future.await;
|
||||
}
|
||||
this.update(&mut cx, |this, cx| this.auto_install_extensions(cx))
|
||||
.ok();
|
||||
this.update(&mut cx, |this, cx| this.check_for_updates(cx))
|
||||
this.update(cx, |this, cx| this.auto_install_extensions(cx))
|
||||
.ok();
|
||||
this.update(cx, |this, cx| this.check_for_updates(cx)).ok();
|
||||
})
|
||||
.detach();
|
||||
|
||||
// Perform all extension loading in a single task to ensure that we
|
||||
// never attempt to simultaneously load/unload extensions from multiple
|
||||
// parallel tasks.
|
||||
this.tasks.push(cx.spawn(|this, mut cx| {
|
||||
this.tasks.push(cx.spawn(async move |this, cx| {
|
||||
async move {
|
||||
load_initial_extensions.await;
|
||||
|
||||
|
@ -330,14 +329,14 @@ impl ExtensionStore {
|
|||
_ = debounce_timer => {
|
||||
if index_changed {
|
||||
let index = this
|
||||
.update(&mut cx, |this, cx| this.rebuild_extension_index(cx))?
|
||||
.update(cx, |this, cx| this.rebuild_extension_index(cx))?
|
||||
.await;
|
||||
this.update(&mut cx, |this, cx| this.extensions_updated(index, cx))?
|
||||
this.update( cx, |this, cx| this.extensions_updated(index, cx))?
|
||||
.await;
|
||||
index_changed = false;
|
||||
}
|
||||
|
||||
Self::update_ssh_clients(&this, &mut cx).await?;
|
||||
Self::update_ssh_clients(&this, cx).await?;
|
||||
}
|
||||
_ = connection_registered_rx.next() => {
|
||||
debounce_timer = cx
|
||||
|
@ -347,7 +346,7 @@ impl ExtensionStore {
|
|||
}
|
||||
extension_id = reload_rx.next() => {
|
||||
let Some(extension_id) = extension_id else { break; };
|
||||
this.update(&mut cx, |this, _| {
|
||||
this.update( cx, |this, _| {
|
||||
this.modified_extensions.extend(extension_id);
|
||||
})?;
|
||||
index_changed = true;
|
||||
|
@ -362,6 +361,7 @@ impl ExtensionStore {
|
|||
anyhow::Ok(())
|
||||
}
|
||||
.map(drop)
|
||||
.await;
|
||||
}));
|
||||
|
||||
// Watch the installed extensions directory for changes. Whenever changes are
|
||||
|
@ -542,9 +542,9 @@ impl ExtensionStore {
|
|||
],
|
||||
cx,
|
||||
);
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let extensions = task.await?;
|
||||
this.update(&mut cx, |this, _cx| {
|
||||
this.update(cx, |this, _cx| {
|
||||
extensions
|
||||
.into_iter()
|
||||
.filter(|extension| {
|
||||
|
@ -589,9 +589,9 @@ impl ExtensionStore {
|
|||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
for extension_id in extensions_to_install {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
this.install_latest_extension(extension_id.clone(), cx);
|
||||
})
|
||||
.ok();
|
||||
|
@ -602,10 +602,8 @@ impl ExtensionStore {
|
|||
|
||||
pub fn check_for_updates(&mut self, cx: &mut Context<Self>) {
|
||||
let task = self.fetch_extensions_with_update_available(cx);
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
Self::upgrade_extensions(this, task.await?, &mut cx).await
|
||||
})
|
||||
.detach();
|
||||
cx.spawn(async move |this, cx| Self::upgrade_extensions(this, task.await?, cx).await)
|
||||
.detach();
|
||||
}
|
||||
|
||||
async fn upgrade_extensions(
|
||||
|
@ -646,7 +644,7 @@ impl ExtensionStore {
|
|||
) -> Task<Result<Vec<ExtensionMetadata>>> {
|
||||
let url = self.http_client.build_zed_api_url(path, query);
|
||||
let http_client = self.http_client.clone();
|
||||
cx.spawn(move |_, _| async move {
|
||||
cx.spawn(async move |_, _| {
|
||||
let mut response = http_client
|
||||
.get(url?.as_ref(), AsyncBody::empty(), true)
|
||||
.await?;
|
||||
|
@ -698,17 +696,12 @@ impl ExtensionStore {
|
|||
};
|
||||
cx.notify();
|
||||
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
let _finish = util::defer({
|
||||
let this = this.clone();
|
||||
let mut cx = cx.clone();
|
||||
cx.spawn(async move |this, cx| {
|
||||
let _finish = cx.on_drop(&this, {
|
||||
let extension_id = extension_id.clone();
|
||||
move || {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.outstanding_operations.remove(extension_id.as_ref());
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
move |this, cx| {
|
||||
this.outstanding_operations.remove(extension_id.as_ref());
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -744,13 +737,13 @@ impl ExtensionStore {
|
|||
let decompressed_bytes = GzipDecoder::new(BufReader::new(tar_gz_bytes.as_slice()));
|
||||
let archive = Archive::new(decompressed_bytes);
|
||||
archive.unpack(extension_dir).await?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.update( cx, |this, cx| {
|
||||
this.reload(Some(extension_id.clone()), cx)
|
||||
})?
|
||||
.await;
|
||||
|
||||
if let ExtensionOperation::Install = operation {
|
||||
this.update(&mut cx, |_, cx| {
|
||||
this.update( cx, |_, cx| {
|
||||
cx.emit(Event::ExtensionInstalled(extension_id));
|
||||
})
|
||||
.ok();
|
||||
|
@ -835,17 +828,12 @@ impl ExtensionStore {
|
|||
btree_map::Entry::Vacant(e) => e.insert(ExtensionOperation::Remove),
|
||||
};
|
||||
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
let _finish = util::defer({
|
||||
let this = this.clone();
|
||||
let mut cx = cx.clone();
|
||||
cx.spawn(async move |this, cx| {
|
||||
let _finish = cx.on_drop(&this, {
|
||||
let extension_id = extension_id.clone();
|
||||
move || {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.outstanding_operations.remove(extension_id.as_ref());
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
move |this, cx| {
|
||||
this.outstanding_operations.remove(extension_id.as_ref());
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -867,8 +855,7 @@ impl ExtensionStore {
|
|||
)
|
||||
.await?;
|
||||
|
||||
this.update(&mut cx, |this, cx| this.reload(None, cx))?
|
||||
.await;
|
||||
this.update(cx, |this, cx| this.reload(None, cx))?.await;
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx)
|
||||
|
@ -883,12 +870,12 @@ impl ExtensionStore {
|
|||
let fs = self.fs.clone();
|
||||
let builder = self.builder.clone();
|
||||
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let mut extension_manifest =
|
||||
ExtensionManifest::load(fs.clone(), &extension_source_path).await?;
|
||||
let extension_id = extension_manifest.id.clone();
|
||||
|
||||
if !this.update(&mut cx, |this, cx| {
|
||||
if !this.update(cx, |this, cx| {
|
||||
match this.outstanding_operations.entry(extension_id.clone()) {
|
||||
btree_map::Entry::Occupied(_) => return false,
|
||||
btree_map::Entry::Vacant(e) => e.insert(ExtensionOperation::Remove),
|
||||
|
@ -899,16 +886,11 @@ impl ExtensionStore {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
let _finish = util::defer({
|
||||
let this = this.clone();
|
||||
let mut cx = cx.clone();
|
||||
let _finish = cx.on_drop(&this, {
|
||||
let extension_id = extension_id.clone();
|
||||
move || {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.outstanding_operations.remove(extension_id.as_ref());
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
move |this, cx| {
|
||||
this.outstanding_operations.remove(extension_id.as_ref());
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -945,8 +927,7 @@ impl ExtensionStore {
|
|||
fs.create_symlink(output_path, extension_source_path)
|
||||
.await?;
|
||||
|
||||
this.update(&mut cx, |this, cx| this.reload(None, cx))?
|
||||
.await;
|
||||
this.update(cx, |this, cx| this.reload(None, cx))?.await;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
@ -973,16 +954,16 @@ impl ExtensionStore {
|
|||
.await
|
||||
});
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let result = compile.await;
|
||||
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
this.outstanding_operations.remove(&extension_id);
|
||||
cx.notify();
|
||||
})?;
|
||||
|
||||
if result.is_ok() {
|
||||
this.update(&mut cx, |this, cx| this.reload(Some(extension_id), cx))?
|
||||
this.update(cx, |this, cx| this.reload(Some(extension_id), cx))?
|
||||
.await;
|
||||
}
|
||||
|
||||
|
@ -1216,7 +1197,7 @@ impl ExtensionStore {
|
|||
cx.notify();
|
||||
cx.emit(Event::ExtensionsUpdated);
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
cx.background_spawn({
|
||||
let fs = fs.clone();
|
||||
async move {
|
||||
|
@ -1263,14 +1244,14 @@ impl ExtensionStore {
|
|||
if let Some(wasm_extension) = wasm_extension.log_err() {
|
||||
wasm_extensions.push((extension.manifest.clone(), wasm_extension));
|
||||
} else {
|
||||
this.update(&mut cx, |_, cx| {
|
||||
this.update(cx, |_, cx| {
|
||||
cx.emit(Event::ExtensionFailedToLoad(extension.manifest.id.clone()))
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
this.reload_complete_senders.clear();
|
||||
|
||||
for (manifest, wasm_extension) in &wasm_extensions {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue