Rename Task -> EntityTask (a BackgroundTask is just a Task)
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
46f8665e41
commit
fda1394057
7 changed files with 28 additions and 30 deletions
|
@ -967,7 +967,7 @@ impl MutableAppContext {
|
|||
self.flush_effects();
|
||||
}
|
||||
|
||||
fn spawn<F, T>(&mut self, future: F) -> Task<Option<T>>
|
||||
fn spawn<F, T>(&mut self, future: F) -> EntityTask<Option<T>>
|
||||
where
|
||||
F: 'static + Future,
|
||||
T: 'static,
|
||||
|
@ -983,7 +983,7 @@ impl MutableAppContext {
|
|||
.map(|result| *result.downcast::<T>().unwrap())
|
||||
})
|
||||
};
|
||||
Task::new(
|
||||
EntityTask::new(
|
||||
task_id,
|
||||
task,
|
||||
TaskHandlerMap::Future(self.future_handlers.clone()),
|
||||
|
@ -991,7 +991,7 @@ impl MutableAppContext {
|
|||
)
|
||||
}
|
||||
|
||||
fn spawn_stream<F, T>(&mut self, mut stream: F) -> Task<Option<T>>
|
||||
fn spawn_stream<F, T>(&mut self, mut stream: F) -> EntityTask<Option<T>>
|
||||
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<S, F, U>(&mut self, future: S, callback: F) -> Task<Option<U>>
|
||||
pub fn spawn<S, F, U>(&mut self, future: S, callback: F) -> EntityTask<Option<U>>
|
||||
where
|
||||
S: 'static + Future,
|
||||
F: 'static + FnOnce(&mut T, S::Output, &mut ModelContext<T>) -> U,
|
||||
|
@ -1594,7 +1594,7 @@ impl<'a, T: Entity> ModelContext<'a, T> {
|
|||
stream: S,
|
||||
mut item_callback: F,
|
||||
done_callback: G,
|
||||
) -> Task<Option<U>>
|
||||
) -> EntityTask<Option<U>>
|
||||
where
|
||||
S: 'static + Stream + Unpin,
|
||||
F: 'static + FnMut(&mut T, S::Item, &mut ModelContext<T>),
|
||||
|
@ -1822,7 +1822,7 @@ impl<'a, T: View> ViewContext<'a, T> {
|
|||
self.halt_stream = true;
|
||||
}
|
||||
|
||||
pub fn spawn<S, F, U>(&mut self, future: S, callback: F) -> Task<Option<U>>
|
||||
pub fn spawn<S, F, U>(&mut self, future: S, callback: F) -> EntityTask<Option<U>>
|
||||
where
|
||||
S: 'static + Future,
|
||||
F: 'static + FnOnce(&mut T, S::Output, &mut ViewContext<T>) -> U,
|
||||
|
@ -1855,7 +1855,7 @@ impl<'a, T: View> ViewContext<'a, T> {
|
|||
stream: S,
|
||||
mut item_callback: F,
|
||||
done_callback: G,
|
||||
) -> Task<Option<U>>
|
||||
) -> EntityTask<Option<U>>
|
||||
where
|
||||
S: 'static + Stream + Unpin,
|
||||
F: 'static + FnMut(&mut T, S::Item, &mut ViewContext<T>),
|
||||
|
@ -2363,7 +2363,7 @@ enum StreamHandler {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub struct Task<T> {
|
||||
pub struct EntityTask<T> {
|
||||
id: usize,
|
||||
task: Option<executor::Task<T>>,
|
||||
handler_map: TaskHandlerMap,
|
||||
|
@ -2376,7 +2376,7 @@ enum TaskHandlerMap {
|
|||
Stream(Rc<RefCell<HashMap<usize, StreamHandler>>>),
|
||||
}
|
||||
|
||||
impl<T> Task<T> {
|
||||
impl<T> EntityTask<T> {
|
||||
fn new(
|
||||
id: usize,
|
||||
task: executor::Task<T>,
|
||||
|
@ -2402,7 +2402,7 @@ impl<T> Task<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Future for Task<T> {
|
||||
impl<T> Future for EntityTask<T> {
|
||||
type Output = T;
|
||||
|
||||
fn poll(
|
||||
|
@ -2414,7 +2414,7 @@ impl<T> Future for Task<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for Task<T> {
|
||||
impl<T> Drop for EntityTask<T> {
|
||||
fn drop(self: &mut Self) {
|
||||
match &self.handler_map {
|
||||
TaskHandlerMap::Detached => {
|
||||
|
|
|
@ -22,9 +22,6 @@ pub struct Background {
|
|||
_stop: channel::Sender<()>,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub type BackgroundTask<T> = smol::Task<T>;
|
||||
|
||||
impl Foreground {
|
||||
pub fn platform(dispatcher: Arc<dyn platform::Dispatcher>) -> Result<Self> {
|
||||
if dispatcher.is_main_thread() {
|
||||
|
@ -82,7 +79,7 @@ impl Background {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn spawn<T>(&self, future: impl Send + Future<Output = T> + 'static) -> BackgroundTask<T>
|
||||
pub fn spawn<T>(&self, future: impl Send + Future<Output = T> + 'static) -> Task<T>
|
||||
where
|
||||
T: 'static + Send,
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Self>) -> Option<BackgroundTask<Result<()>>> {
|
||||
pub fn save(&self, ctx: &mut ModelContext<Self>) -> Option<Task<Result<()>>> {
|
||||
if let Some(file) = &self.file {
|
||||
let snapshot = self.snapshot();
|
||||
Some(file.save(snapshot, ctx.app()))
|
||||
|
|
|
@ -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<BackgroundTask<Result<()>>> {
|
||||
fn save(&self, ctx: &mut MutableAppContext) -> Option<Task<Result<()>>> {
|
||||
self.buffer.update(ctx, |buffer, ctx| buffer.save(ctx))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<BackgroundTask<anyhow::Result<()>>> {
|
||||
fn save(&self, _: &mut MutableAppContext) -> Option<Task<anyhow::Result<()>>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ pub trait ItemViewHandle: Send + Sync {
|
|||
fn set_parent_pane(&self, pane: &ViewHandle<Pane>, app: &mut MutableAppContext);
|
||||
fn id(&self) -> usize;
|
||||
fn to_any(&self) -> AnyViewHandle;
|
||||
fn save(&self, ctx: &mut MutableAppContext) -> Option<BackgroundTask<anyhow::Result<()>>>;
|
||||
fn save(&self, ctx: &mut MutableAppContext) -> Option<Task<anyhow::Result<()>>>;
|
||||
}
|
||||
|
||||
impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
||||
|
@ -71,7 +71,7 @@ impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
|||
})
|
||||
}
|
||||
|
||||
fn save(&self, ctx: &mut MutableAppContext) -> Option<BackgroundTask<anyhow::Result<()>>> {
|
||||
fn save(&self, ctx: &mut MutableAppContext) -> Option<Task<anyhow::Result<()>>> {
|
||||
self.update(ctx, |item, ctx| item.save(ctx.app_mut()))
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Result<()>> {
|
||||
) -> Task<Result<()>> {
|
||||
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<Result<()>> {
|
||||
pub fn save<'a>(&self, content: Snapshot, ctx: &AppContext) -> Task<Result<()>> {
|
||||
let worktree = self.worktree.as_ref(ctx);
|
||||
worktree.save(self.entry_id, content, ctx)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue