diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 52363a9d12..125f749c53 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -967,7 +967,7 @@ impl MutableAppContext { self.flush_effects(); } - fn spawn(&mut self, future: F) -> Task> + fn spawn(&mut self, future: F) -> EntityTask> where F: 'static + Future, T: 'static, @@ -983,7 +983,7 @@ impl MutableAppContext { .map(|result| *result.downcast::().unwrap()) }) }; - Task::new( + EntityTask::new( task_id, task, TaskHandlerMap::Future(self.future_handlers.clone()), @@ -991,7 +991,7 @@ impl MutableAppContext { ) } - fn spawn_stream(&mut self, mut stream: F) -> Task> + fn spawn_stream(&mut self, mut stream: F) -> EntityTask> where F: 'static + Stream + Unpin, T: 'static, @@ -1021,7 +1021,7 @@ impl MutableAppContext { }) }; - Task::new( + EntityTask::new( task_id, task, TaskHandlerMap::Stream(self.stream_handlers.clone()), @@ -1562,7 +1562,7 @@ impl<'a, T: Entity> ModelContext<'a, T> { }); } - pub fn spawn(&mut self, future: S, callback: F) -> Task> + pub fn spawn(&mut self, future: S, callback: F) -> EntityTask> where S: 'static + Future, F: 'static + FnOnce(&mut T, S::Output, &mut ModelContext) -> U, @@ -1594,7 +1594,7 @@ impl<'a, T: Entity> ModelContext<'a, T> { stream: S, mut item_callback: F, done_callback: G, - ) -> Task> + ) -> EntityTask> where S: 'static + Stream + Unpin, F: 'static + FnMut(&mut T, S::Item, &mut ModelContext), @@ -1822,7 +1822,7 @@ impl<'a, T: View> ViewContext<'a, T> { self.halt_stream = true; } - pub fn spawn(&mut self, future: S, callback: F) -> Task> + pub fn spawn(&mut self, future: S, callback: F) -> EntityTask> where S: 'static + Future, F: 'static + FnOnce(&mut T, S::Output, &mut ViewContext) -> U, @@ -1855,7 +1855,7 @@ impl<'a, T: View> ViewContext<'a, T> { stream: S, mut item_callback: F, done_callback: G, - ) -> Task> + ) -> EntityTask> where S: 'static + Stream + Unpin, F: 'static + FnMut(&mut T, S::Item, &mut ViewContext), @@ -2363,7 +2363,7 @@ enum StreamHandler { } #[must_use] -pub struct Task { +pub struct EntityTask { id: usize, task: Option>, handler_map: TaskHandlerMap, @@ -2376,7 +2376,7 @@ enum TaskHandlerMap { Stream(Rc>>), } -impl Task { +impl EntityTask { fn new( id: usize, task: executor::Task, @@ -2402,7 +2402,7 @@ impl Task { } } -impl Future for Task { +impl Future for EntityTask { type Output = T; fn poll( @@ -2414,7 +2414,7 @@ impl Future for Task { } } -impl Drop for Task { +impl Drop for EntityTask { fn drop(self: &mut Self) { match &self.handler_map { TaskHandlerMap::Detached => { diff --git a/gpui/src/executor.rs b/gpui/src/executor.rs index 89c3211a7a..3fe6370d26 100644 --- a/gpui/src/executor.rs +++ b/gpui/src/executor.rs @@ -22,9 +22,6 @@ pub struct Background { _stop: channel::Sender<()>, } -#[must_use] -pub type BackgroundTask = smol::Task; - impl Foreground { pub fn platform(dispatcher: Arc) -> Result { if dispatcher.is_main_thread() { @@ -82,7 +79,7 @@ impl Background { } } - pub fn spawn(&self, future: impl Send + Future + 'static) -> BackgroundTask + pub fn spawn(&self, future: impl Send + Future + 'static) -> Task where T: 'static + Send, { diff --git a/gpui/src/lib.rs b/gpui/src/lib.rs index 285e2a4239..bdf7096506 100644 --- a/gpui/src/lib.rs +++ b/gpui/src/lib.rs @@ -17,6 +17,7 @@ pub use text_layout::TextLayoutCache; mod util; pub use elements::{Element, ElementBox}; pub mod executor; +pub use executor::Task; pub mod keymap; pub mod platform; pub use pathfinder_color as color; diff --git a/zed/src/editor/buffer/mod.rs b/zed/src/editor/buffer/mod.rs index 36096476bb..374343c237 100644 --- a/zed/src/editor/buffer/mod.rs +++ b/zed/src/editor/buffer/mod.rs @@ -14,7 +14,7 @@ use crate::{ worktree::FileHandle, }; use anyhow::{anyhow, Result}; -use gpui::{executor::BackgroundTask, AppContext, Entity, ModelContext}; +use gpui::{AppContext, Entity, ModelContext, Task}; use lazy_static::lazy_static; use rand::prelude::*; use std::{ @@ -241,7 +241,7 @@ impl Buffer { } } - pub fn save(&self, ctx: &mut ModelContext) -> Option>> { + pub fn save(&self, ctx: &mut ModelContext) -> Option>> { if let Some(file) = &self.file { let snapshot = self.snapshot(); Some(file.save(snapshot, ctx.app())) diff --git a/zed/src/editor/buffer_view.rs b/zed/src/editor/buffer_view.rs index cd0fdd6a7c..f744ee8a19 100644 --- a/zed/src/editor/buffer_view.rs +++ b/zed/src/editor/buffer_view.rs @@ -5,9 +5,9 @@ use super::{ use crate::{settings::Settings, watch, workspace}; use anyhow::Result; use gpui::{ - executor::BackgroundTask, fonts::Properties as FontProperties, keymap::Binding, text_layout, - App, AppContext, Element, ElementBox, Entity, FontCache, ModelHandle, MutableAppContext, View, - ViewContext, WeakViewHandle, + fonts::Properties as FontProperties, keymap::Binding, text_layout, App, AppContext, Element, + ElementBox, Entity, FontCache, ModelHandle, MutableAppContext, Task, View, ViewContext, + WeakViewHandle, }; use gpui::{geometry::vector::Vector2F, TextLayoutCache}; use parking_lot::Mutex; @@ -1180,7 +1180,7 @@ impl workspace::ItemView for BufferView { Some(clone) } - fn save(&self, ctx: &mut MutableAppContext) -> Option>> { + fn save(&self, ctx: &mut MutableAppContext) -> Option>> { self.buffer.update(ctx, |buffer, ctx| buffer.save(ctx)) } } diff --git a/zed/src/workspace/workspace_view.rs b/zed/src/workspace/workspace_view.rs index 555dc99a05..1f442866d2 100644 --- a/zed/src/workspace/workspace_view.rs +++ b/zed/src/workspace/workspace_view.rs @@ -1,8 +1,8 @@ use super::{pane, Pane, PaneGroup, SplitDirection, Workspace}; use crate::{settings::Settings, watch}; use gpui::{ - color::rgbu, elements::*, executor::BackgroundTask, keymap::Binding, AnyViewHandle, App, - AppContext, Entity, ModelHandle, MutableAppContext, View, ViewContext, ViewHandle, + color::rgbu, elements::*, keymap::Binding, AnyViewHandle, App, AppContext, Entity, ModelHandle, + MutableAppContext, Task, View, ViewContext, ViewHandle, }; use log::{error, info}; use std::{collections::HashSet, path::PathBuf}; @@ -22,7 +22,7 @@ pub trait ItemView: View { { None } - fn save(&self, _: &mut MutableAppContext) -> Option>> { + fn save(&self, _: &mut MutableAppContext) -> Option>> { None } } @@ -35,7 +35,7 @@ pub trait ItemViewHandle: Send + Sync { fn set_parent_pane(&self, pane: &ViewHandle, app: &mut MutableAppContext); fn id(&self) -> usize; fn to_any(&self) -> AnyViewHandle; - fn save(&self, ctx: &mut MutableAppContext) -> Option>>; + fn save(&self, ctx: &mut MutableAppContext) -> Option>>; } impl ItemViewHandle for ViewHandle { @@ -71,7 +71,7 @@ impl ItemViewHandle for ViewHandle { }) } - fn save(&self, ctx: &mut MutableAppContext) -> Option>> { + fn save(&self, ctx: &mut MutableAppContext) -> Option>> { self.update(ctx, |item, ctx| item.save(ctx.app_mut())) } diff --git a/zed/src/worktree/worktree.rs b/zed/src/worktree/worktree.rs index a48bfc13ae..bbb264df62 100644 --- a/zed/src/worktree/worktree.rs +++ b/zed/src/worktree/worktree.rs @@ -11,7 +11,7 @@ use crate::{ use anyhow::{anyhow, Result}; use crossbeam_channel as channel; use easy_parallel::Parallel; -use gpui::{executor::BackgroundTask, AppContext, Entity, ModelContext, ModelHandle}; +use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task}; use ignore::dir::{Ignore, IgnoreBuilder}; use parking_lot::RwLock; use smol::prelude::*; @@ -356,7 +356,7 @@ impl Worktree { entry_id: usize, content: Snapshot, ctx: &AppContext, - ) -> BackgroundTask> { + ) -> Task> { let path = self.abs_entry_path(entry_id); ctx.background_executor().spawn(async move { let buffer_size = content.text_summary().bytes.min(10 * 1024); @@ -468,7 +468,7 @@ impl FileHandle { self.worktree.as_ref(app).load_history(self.entry_id) } - pub fn save<'a>(&self, content: Snapshot, ctx: &AppContext) -> BackgroundTask> { + pub fn save<'a>(&self, content: Snapshot, ctx: &AppContext) -> Task> { let worktree = self.worktree.as_ref(ctx); worktree.save(self.entry_id, content, ctx) }