From 914cf37f3717b2cf215d25740956fbf85d7a0e44 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 2 Apr 2021 11:02:09 -0600 Subject: [PATCH] Remove executor::ForegroundTask wrapper Now that smol returns the same Task as async_task, we can simply re-export the async_task::Task struct from our executor module. Co-Authored-By: Max Brunsfeld --- Cargo.lock | 35 ++++--------------------------- Cargo.toml | 3 +++ gpui/Cargo.toml | 3 +-- gpui/src/app.rs | 14 ++++++------- gpui/src/executor.rs | 49 ++++---------------------------------------- 5 files changed, 19 insertions(+), 85 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 602b2d6db4..2012a546c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,7 +59,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" dependencies = [ - "async-task 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "async-task", "concurrent-queue", "fastrand", "futures-lite", @@ -138,13 +138,7 @@ dependencies = [ [[package]] name = "async-task" version = "4.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" - -[[package]] -name = "async-task" -version = "4.0.3" -source = "git+https://github.com/zedit-io/async-task?rev=341b57d6de98cdfd7b418567b8de2022ca993a6e#341b57d6de98cdfd7b418567b8de2022ca993a6e" +source = "git+https://github.com/zed-industries/async-task?rev=341b57d6de98cdfd7b418567b8de2022ca993a6e#341b57d6de98cdfd7b418567b8de2022ca993a6e" [[package]] name = "atomic-waker" @@ -228,7 +222,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" dependencies = [ "async-channel", - "async-task 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "async-task", "atomic-waker", "fastrand", "futures-lite", @@ -781,7 +775,7 @@ name = "gpui" version = "0.1.0" dependencies = [ "anyhow", - "async-task 4.0.3 (git+https://github.com/zedit-io/async-task?rev=341b57d6de98cdfd7b418567b8de2022ca993a6e)", + "async-task", "bindgen", "cc", "cocoa", @@ -800,7 +794,6 @@ dependencies = [ "parking_lot", "pathfinder_color", "pathfinder_geometry", - "pin-project", "png", "rand 0.8.3", "replace_with", @@ -1106,26 +1099,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -[[package]] -name = "pin-project" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "pin-project-lite" version = "0.2.4" diff --git a/Cargo.toml b/Cargo.toml index 843d72b73e..83f3ad985a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,5 @@ [workspace] members = ["zed", "gpui"] + +[patch.crates-io] +async-task = {git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e"} diff --git a/gpui/Cargo.toml b/gpui/Cargo.toml index 98b53af757..6f883f5dfd 100644 --- a/gpui/Cargo.toml +++ b/gpui/Cargo.toml @@ -5,7 +5,7 @@ name = "gpui" version = "0.1.0" [dependencies] -async-task = {git = "https://github.com/zedit-io/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e"} +async-task = "4.0.3" ctor = "0.1" etagere = "0.2" num_cpus = "1.13" @@ -13,7 +13,6 @@ ordered-float = "2.1.1" parking_lot = "0.11.1" pathfinder_color = "0.5" pathfinder_geometry = "0.5" -pin-project = "1.0.5" rand = "0.8.3" replace_with = "0.1.7" smallvec = "1.6.1" diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 6a801812d1..b18830061f 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -1,6 +1,6 @@ use crate::{ elements::ElementBox, - executor::{self, ForegroundTask}, + executor::{self, Task}, keymap::{self, Keystroke}, platform::{self, App as _, WindowOptions}, presenter::Presenter, @@ -963,7 +963,7 @@ impl MutableAppContext { self.flush_effects(); } - fn spawn(&mut self, future: F) -> (usize, ForegroundTask>) + fn spawn(&mut self, future: F) -> (usize, Task>) where F: 'static + Future, T: 'static, @@ -979,7 +979,7 @@ impl MutableAppContext { (task_id, task) } - fn spawn_stream(&mut self, mut stream: F) -> (usize, ForegroundTask>) + fn spawn_stream(&mut self, mut stream: F) -> (usize, Task>) where F: 'static + Stream + Unpin, T: 'static, @@ -1525,7 +1525,7 @@ impl<'a, T: Entity> ModelContext<'a, T> { }); } - pub fn spawn(&mut self, future: S, callback: F) -> ForegroundTask> + pub fn spawn(&mut self, future: S, callback: F) -> Task> where S: 'static + Future, F: 'static + FnOnce(&mut T, S::Output, &mut ModelContext) -> U, @@ -1557,7 +1557,7 @@ impl<'a, T: Entity> ModelContext<'a, T> { stream: S, mut item_callback: F, done_callback: G, - ) -> ForegroundTask> + ) -> Task> where S: 'static + Stream + Unpin, F: 'static + FnMut(&mut T, S::Item, &mut ModelContext), @@ -1785,7 +1785,7 @@ impl<'a, T: View> ViewContext<'a, T> { self.halt_stream = true; } - pub fn spawn(&mut self, future: S, callback: F) -> ForegroundTask> + pub fn spawn(&mut self, future: S, callback: F) -> Task> where S: 'static + Future, F: 'static + FnOnce(&mut T, S::Output, &mut ViewContext) -> U, @@ -1818,7 +1818,7 @@ impl<'a, T: View> ViewContext<'a, T> { stream: S, mut item_callback: F, done_callback: G, - ) -> ForegroundTask> + ) -> Task> where S: 'static + Stream + Unpin, F: 'static + FnMut(&mut T, S::Item, &mut ViewContext), diff --git a/gpui/src/executor.rs b/gpui/src/executor.rs index 618bbe059c..89c3211a7a 100644 --- a/gpui/src/executor.rs +++ b/gpui/src/executor.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Result}; use async_task::Runnable; -use pin_project::pin_project; +pub use async_task::Task; use smol::prelude::*; use smol::{channel, Executor}; use std::rc::Rc; @@ -17,27 +17,6 @@ pub enum Foreground { Test(smol::LocalExecutor<'static>), } -#[must_use] -#[pin_project(project = ForegroundTaskProject)] -pub enum ForegroundTask { - Platform(#[pin] async_task::Task), - Test(#[pin] smol::Task), -} - -impl Future for ForegroundTask { - type Output = T; - - fn poll( - self: std::pin::Pin<&mut Self>, - ctx: &mut std::task::Context<'_>, - ) -> std::task::Poll { - match self.project() { - ForegroundTaskProject::Platform(task) => task.poll(ctx), - ForegroundTaskProject::Test(task) => task.poll(ctx), - } - } -} - pub struct Background { executor: Arc>, _stop: channel::Sender<()>, @@ -62,19 +41,16 @@ impl Foreground { Self::Test(smol::LocalExecutor::new()) } - pub fn spawn( - &self, - future: impl Future + 'static, - ) -> ForegroundTask { + pub fn spawn(&self, future: impl Future + 'static) -> Task { match self { Self::Platform { dispatcher, .. } => { let dispatcher = dispatcher.clone(); let schedule = move |runnable: Runnable| dispatcher.run_on_main_thread(runnable); let (runnable, task) = async_task::spawn_local(future, schedule); runnable.schedule(); - ForegroundTask::Platform(task) + task } - Self::Test(executor) => ForegroundTask::Test(executor.spawn(future)), + Self::Test(executor) => executor.spawn(future), } } @@ -86,23 +62,6 @@ impl Foreground { } } -#[must_use] -impl ForegroundTask { - pub fn detach(self) { - match self { - Self::Platform(task) => task.detach(), - Self::Test(task) => task.detach(), - } - } - - pub async fn cancel(self) -> Option { - match self { - Self::Platform(task) => task.cancel().await, - Self::Test(task) => task.cancel().await, - } - } -} - impl Background { pub fn new() -> Self { let executor = Arc::new(Executor::new());