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
|
@ -118,7 +118,7 @@ impl NativeRunningKernel {
|
|||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Task<Result<Box<dyn RunningKernel>>> {
|
||||
window.spawn(cx, |cx| async move {
|
||||
window.spawn(cx, async move |cx| {
|
||||
let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
|
||||
let ports = peek_ports(ip).await?;
|
||||
|
||||
|
@ -177,10 +177,10 @@ impl NativeRunningKernel {
|
|||
cx.spawn({
|
||||
let session = session.clone();
|
||||
|
||||
|mut cx| async move {
|
||||
async move |cx| {
|
||||
while let Some(message) = messages_rx.next().await {
|
||||
session
|
||||
.update_in(&mut cx, |session, window, cx| {
|
||||
.update_in(cx, |session, window, cx| {
|
||||
session.route(&message, window, cx);
|
||||
})
|
||||
.ok();
|
||||
|
@ -194,10 +194,10 @@ impl NativeRunningKernel {
|
|||
cx.spawn({
|
||||
let session = session.clone();
|
||||
|
||||
|mut cx| async move {
|
||||
async move |cx| {
|
||||
while let Ok(message) = iopub_socket.read().await {
|
||||
session
|
||||
.update_in(&mut cx, |session, window, cx| {
|
||||
.update_in(cx, |session, window, cx| {
|
||||
session.route(&message, window, cx);
|
||||
})
|
||||
.ok();
|
||||
|
@ -253,7 +253,7 @@ impl NativeRunningKernel {
|
|||
|
||||
let stderr = process.stderr.take();
|
||||
|
||||
cx.spawn(|mut _cx| async move {
|
||||
cx.spawn(async move |_cx| {
|
||||
if stderr.is_none() {
|
||||
return;
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ impl NativeRunningKernel {
|
|||
|
||||
let stdout = process.stdout.take();
|
||||
|
||||
cx.spawn(|mut _cx| async move {
|
||||
cx.spawn(async move |_cx| {
|
||||
if stdout.is_none() {
|
||||
return;
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ impl NativeRunningKernel {
|
|||
|
||||
let status = process.status();
|
||||
|
||||
let process_status_task = cx.spawn(|mut cx| async move {
|
||||
let process_status_task = cx.spawn(async move |cx| {
|
||||
let error_message = match status.await {
|
||||
Ok(status) => {
|
||||
if status.success() {
|
||||
|
@ -299,7 +299,7 @@ impl NativeRunningKernel {
|
|||
log::error!("{}", error_message);
|
||||
|
||||
session
|
||||
.update(&mut cx, |session, cx| {
|
||||
.update(cx, |session, cx| {
|
||||
session.kernel_errored(error_message, cx);
|
||||
|
||||
cx.notify();
|
||||
|
|
|
@ -148,7 +148,7 @@ impl RemoteRunningKernel {
|
|||
|
||||
let http_client = cx.http_client();
|
||||
|
||||
window.spawn(cx, |cx| async move {
|
||||
window.spawn(cx, async move |cx| {
|
||||
let kernel_id = launch_remote_kernel(
|
||||
&remote_server,
|
||||
http_client.clone(),
|
||||
|
@ -201,12 +201,12 @@ impl RemoteRunningKernel {
|
|||
let receiving_task = cx.spawn({
|
||||
let session = session.clone();
|
||||
|
||||
|mut cx| async move {
|
||||
async move |cx| {
|
||||
while let Some(message) = r.next().await {
|
||||
match message {
|
||||
Ok(message) => {
|
||||
session
|
||||
.update_in(&mut cx, |session, window, cx| {
|
||||
.update_in(cx, |session, window, cx| {
|
||||
session.route(&message, window, cx);
|
||||
})
|
||||
.ok();
|
||||
|
@ -281,7 +281,7 @@ impl RunningKernel for RemoteRunningKernel {
|
|||
let token = self.remote_server.token.clone();
|
||||
let http_client = self.http_client.clone();
|
||||
|
||||
window.spawn(cx, |_| async move {
|
||||
window.spawn(cx, async move |_| {
|
||||
let request = Request::builder()
|
||||
.method("DELETE")
|
||||
.uri(&url)
|
||||
|
|
|
@ -132,14 +132,14 @@ impl Cell {
|
|||
let languages = languages.clone();
|
||||
let source = source.clone();
|
||||
|
||||
cx.spawn_in(window, |this, mut cx| async move {
|
||||
cx.spawn_in(window, async move |this, cx| {
|
||||
let parsed_markdown = cx
|
||||
.background_spawn(async move {
|
||||
parse_markdown(&source, None, Some(languages)).await
|
||||
})
|
||||
.await;
|
||||
|
||||
this.update(&mut cx, |cell: &mut MarkdownCell, _| {
|
||||
this.update(cx, |cell: &mut MarkdownCell, _| {
|
||||
cell.parsed_markdown = Some(parsed_markdown);
|
||||
})
|
||||
.log_err();
|
||||
|
@ -200,10 +200,10 @@ impl Cell {
|
|||
});
|
||||
|
||||
let buffer = buffer.clone();
|
||||
let language_task = cx.spawn_in(window, |this, mut cx| async move {
|
||||
let language_task = cx.spawn_in(window, async move |this, cx| {
|
||||
let language = notebook_language.await;
|
||||
|
||||
buffer.update(&mut cx, |buffer, cx| {
|
||||
buffer.update(cx, |buffer, cx| {
|
||||
buffer.set_language(language.clone(), cx);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -92,7 +92,9 @@ impl NotebookEditor {
|
|||
let language_name = notebook_item.read(cx).language_name();
|
||||
|
||||
let notebook_language = notebook_item.read(cx).notebook_language();
|
||||
let notebook_language = cx.spawn_in(window, |_, _| notebook_language).shared();
|
||||
let notebook_language = cx
|
||||
.spawn_in(window, async move |_, _| notebook_language.await)
|
||||
.shared();
|
||||
|
||||
let mut cell_order = vec![]; // Vec<CellId>
|
||||
let mut cell_map = HashMap::default(); // HashMap<CellId, Cell>
|
||||
|
@ -570,9 +572,9 @@ impl project::ProjectItem for NotebookItem {
|
|||
let languages = project.read(cx).languages().clone();
|
||||
|
||||
if path.path.extension().unwrap_or_default() == "ipynb" {
|
||||
Some(cx.spawn(|mut cx| async move {
|
||||
Some(cx.spawn(async move |cx| {
|
||||
let abs_path = project
|
||||
.read_with(&cx, |project, cx| project.absolute_path(&path, cx))?
|
||||
.read_with(cx, |project, cx| project.absolute_path(&path, cx))?
|
||||
.ok_or_else(|| anyhow::anyhow!("Failed to find the absolute path"))?;
|
||||
|
||||
// todo: watch for changes to the file
|
||||
|
@ -595,7 +597,7 @@ impl project::ProjectItem for NotebookItem {
|
|||
};
|
||||
|
||||
let id = project
|
||||
.update(&mut cx, |project, cx| project.entry_for_path(&path, cx))?
|
||||
.update(cx, |project, cx| project.entry_for_path(&path, cx))?
|
||||
.context("Entry not found")?
|
||||
.id;
|
||||
|
||||
|
|
|
@ -17,20 +17,18 @@ pub struct MarkdownView {
|
|||
|
||||
impl MarkdownView {
|
||||
pub fn from(text: String, cx: &mut Context<Self>) -> Self {
|
||||
let task = cx.spawn(|markdown_view, mut cx| {
|
||||
let parsed = {
|
||||
let text = text.clone();
|
||||
let parsed =
|
||||
cx.background_spawn(async move { parse_markdown(&text, None, None).await });
|
||||
cx.background_spawn(async move { parse_markdown(&text.clone(), None, None).await })
|
||||
};
|
||||
let task = cx.spawn(async move |markdown_view, cx| {
|
||||
let content = parsed.await;
|
||||
|
||||
async move {
|
||||
let content = parsed.await;
|
||||
|
||||
markdown_view.update(&mut cx, |markdown, cx| {
|
||||
markdown.parsing_markdown_task.take();
|
||||
markdown.contents = Some(content);
|
||||
cx.notify();
|
||||
})
|
||||
}
|
||||
markdown_view.update(cx, |markdown, cx| {
|
||||
markdown.parsing_markdown_task.take();
|
||||
markdown.contents = Some(content);
|
||||
cx.notify();
|
||||
})
|
||||
});
|
||||
|
||||
Self {
|
||||
|
|
|
@ -122,12 +122,12 @@ impl ReplStore {
|
|||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<()>> {
|
||||
let kernel_specifications = python_env_kernel_specifications(project, worktree_id, cx);
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let kernel_specifications = kernel_specifications
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to get python kernelspecs: {:?}", e))?;
|
||||
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
this.kernel_specifications_for_worktree
|
||||
.insert(worktree_id, kernel_specifications);
|
||||
cx.notify();
|
||||
|
@ -149,7 +149,7 @@ impl ReplStore {
|
|||
token,
|
||||
};
|
||||
let http_client = cx.http_client();
|
||||
Some(cx.spawn(|_, _| async move {
|
||||
Some(cx.spawn(async move |_, _| {
|
||||
list_remote_kernelspecs(remote_server, http_client)
|
||||
.await
|
||||
.map(|specs| specs.into_iter().map(KernelSpecification::Remote).collect())
|
||||
|
@ -180,11 +180,11 @@ impl ReplStore {
|
|||
anyhow::Ok(all_specs)
|
||||
});
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let all_specs = all_specs.await;
|
||||
|
||||
if let Ok(specs) = all_specs {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
this.kernel_specifications = specs;
|
||||
cx.notify();
|
||||
})
|
||||
|
|
|
@ -268,18 +268,18 @@ impl Session {
|
|||
};
|
||||
|
||||
let pending_kernel = cx
|
||||
.spawn(|this, mut cx| async move {
|
||||
.spawn(async move |this, cx| {
|
||||
let kernel = kernel.await;
|
||||
|
||||
match kernel {
|
||||
Ok(kernel) => {
|
||||
this.update(&mut cx, |session, cx| {
|
||||
this.update(cx, |session, cx| {
|
||||
session.kernel(Kernel::RunningKernel(kernel), cx);
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
Err(err) => {
|
||||
this.update(&mut cx, |session, cx| {
|
||||
this.update(cx, |session, cx| {
|
||||
session.kernel_errored(err.to_string(), cx);
|
||||
})
|
||||
.ok();
|
||||
|
@ -463,9 +463,9 @@ impl Session {
|
|||
let task = task.clone();
|
||||
let message = message.clone();
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
task.await;
|
||||
this.update(&mut cx, |session, cx| {
|
||||
this.update(cx, |session, cx| {
|
||||
session.send(message, cx).ok();
|
||||
})
|
||||
.ok();
|
||||
|
@ -573,7 +573,7 @@ impl Session {
|
|||
|
||||
let forced = kernel.force_shutdown(window, cx);
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let message: JupyterMessage = ShutdownRequest { restart: false }.into();
|
||||
request_tx.try_send(message).ok();
|
||||
|
||||
|
@ -582,7 +582,7 @@ impl Session {
|
|||
// Give the kernel a bit of time to clean up
|
||||
cx.background_executor().timer(Duration::from_secs(3)).await;
|
||||
|
||||
this.update(&mut cx, |session, cx| {
|
||||
this.update(cx, |session, cx| {
|
||||
session.clear_outputs(cx);
|
||||
session.kernel(Kernel::Shutdown, cx);
|
||||
cx.notify();
|
||||
|
@ -610,7 +610,7 @@ impl Session {
|
|||
|
||||
let forced = kernel.force_shutdown(window, cx);
|
||||
|
||||
cx.spawn_in(window, |this, mut cx| async move {
|
||||
cx.spawn_in(window, async move |this, cx| {
|
||||
// Send shutdown request with restart flag
|
||||
log::debug!("restarting kernel");
|
||||
let message: JupyterMessage = ShutdownRequest { restart: true }.into();
|
||||
|
@ -623,7 +623,7 @@ impl Session {
|
|||
forced.await.log_err();
|
||||
|
||||
// Start a new kernel
|
||||
this.update_in(&mut cx, |session, window, cx| {
|
||||
this.update_in(cx, |session, window, cx| {
|
||||
// TODO: Differentiate between restart and restart+clear-outputs
|
||||
session.clear_outputs(cx);
|
||||
session.start_kernel(window, cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue