From bfa83ae343058dddf073f36266a8c4c2ad24a48d Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Fri, 28 May 2021 11:02:31 +0200 Subject: [PATCH] move async_job abstraction into `asyncgit` for now --- Cargo.lock | 12 ------ Cargo.toml | 4 +- Makefile | 4 +- async_utils/Cargo.toml | 21 ---------- async_utils/LICENSE.md | 1 - async_utils/src/error.rs | 21 ---------- .../lib.rs => asyncgit/src/asyncjob/mod.rs | 39 +++++-------------- asyncgit/src/error.rs | 6 +++ asyncgit/src/lib.rs | 1 + src/components/syntax_text.rs | 2 +- src/ui/syntax_text.rs | 2 +- 11 files changed, 22 insertions(+), 91 deletions(-) delete mode 100644 async_utils/Cargo.toml delete mode 120000 async_utils/LICENSE.md delete mode 100644 async_utils/src/error.rs rename async_utils/src/lib.rs => asyncgit/src/asyncjob/mod.rs (86%) diff --git a/Cargo.lock b/Cargo.lock index f75f2f34..899caa16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,17 +59,6 @@ dependencies = [ "nodrop", ] -[[package]] -name = "async_utils" -version = "0.1.0" -dependencies = [ - "crossbeam-channel", - "log", - "pretty_assertions", - "rayon-core", - "thiserror", -] - [[package]] name = "asyncgit" version = "0.16.0" @@ -478,7 +467,6 @@ name = "gitui" version = "0.15.0" dependencies = [ "anyhow", - "async_utils", "asyncgit", "backtrace", "bitflags", diff --git a/Cargo.toml b/Cargo.toml index a43f9faa..0c53a689 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,8 @@ keywords = [ [dependencies] scopetime = { path = "./scopetime", version = "0.1" } -asyncgit = { path = "./asyncgit" } +asyncgit = { path = "./asyncgit", version = "0.16" } filetree = { path = "./filetree" } -async_utils = { path = "./async_utils" } crossterm = { version = "0.19", features = [ "serde" ] } clap = { version = "2.33", default-features = false } tui = { version = "0.15", default-features = false, features = ['crossterm', 'serde'] } @@ -67,7 +66,6 @@ timing=["scopetime/enabled"] members=[ "asyncgit", "scopetime", - "async_utils", "filetree", ] diff --git a/Makefile b/Makefile index 051df94c..8839c60b 100644 --- a/Makefile +++ b/Makefile @@ -45,12 +45,12 @@ fmt: clippy: touch src/main.rs - cargo clean -p gitui -p asyncgit -p scopetime -p filetree -p async_utils + cargo clean -p gitui -p asyncgit -p scopetime -p filetree cargo clippy --workspace --all-features clippy-nightly: touch src/main.rs - cargo clean -p gitui -p asyncgit -p scopetime -p filetree -p async_utils + cargo clean -p gitui -p asyncgit -p scopetime -p filetree cargo +nightly clippy --workspace --all-features check: fmt clippy test diff --git a/async_utils/Cargo.toml b/async_utils/Cargo.toml deleted file mode 100644 index b4b22cbb..00000000 --- a/async_utils/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "async_utils" -version = "0.1.0" -authors = ["Stephan Dilly "] -edition = "2018" -description = "async job utils" -homepage = "https://github.com/extrawurst/gitui" -repository = "https://github.com/extrawurst/gitui" -readme = "README.md" -license-file = "LICENSE.md" -categories = ["asynchronous","concurrency"] -keywords = ["parallel", "thread", "concurrency", "performance"] - -[dependencies] -rayon-core = "1.9" -crossbeam-channel = "0.5" -log = "0.4" -thiserror = "1.0" - -[dev-dependencies] -pretty_assertions = "0.7" \ No newline at end of file diff --git a/async_utils/LICENSE.md b/async_utils/LICENSE.md deleted file mode 120000 index 7eabdb1c..00000000 --- a/async_utils/LICENSE.md +++ /dev/null @@ -1 +0,0 @@ -../LICENSE.md \ No newline at end of file diff --git a/async_utils/src/error.rs b/async_utils/src/error.rs deleted file mode 100644 index bd9e9020..00000000 --- a/async_utils/src/error.rs +++ /dev/null @@ -1,21 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum Error { - #[error("`{0}`")] - Generic(String), -} - -pub type Result = std::result::Result; - -impl From> for Error { - fn from(error: crossbeam_channel::SendError) -> Self { - Self::Generic(format!("send error: {}", error)) - } -} - -impl From> for Error { - fn from(error: std::sync::PoisonError) -> Self { - Self::Generic(format!("poison error: {}", error)) - } -} diff --git a/async_utils/src/lib.rs b/asyncgit/src/asyncjob/mod.rs similarity index 86% rename from async_utils/src/lib.rs rename to asyncgit/src/asyncjob/mod.rs index d2408002..3b48787c 100644 --- a/async_utils/src/lib.rs +++ b/asyncgit/src/asyncjob/mod.rs @@ -1,35 +1,19 @@ -// #![forbid(missing_docs)] -#![deny(unsafe_code)] -#![deny( - unused_imports, - unused_must_use, - dead_code, - unstable_name_collisions, - unused_assignments -)] -#![deny(unstable_name_collisions)] -#![deny(clippy::all, clippy::perf, clippy::nursery, clippy::pedantic)] +//! provides `AsyncJob` trait and `AsyncSingleJob` struct + #![deny(clippy::expect_used)] -#![deny(clippy::filetype_is_file)] -#![deny(clippy::cargo)] -#![deny(clippy::unwrap_used)] -#![deny(clippy::panic)] -#![deny(clippy::match_like_matches_macro)] -#![deny(clippy::needless_update)] -#![allow(clippy::module_name_repetitions)] -#![allow(clippy::must_use_candidate)] -#![allow(clippy::missing_errors_doc)] - -mod error; +use crate::error::Result; use crossbeam_channel::Sender; -use error::Result; use std::sync::{Arc, Mutex}; +/// trait that defines an async task we can run on a threadpool pub trait AsyncJob: Send + Sync + Clone { + /// can run a synchronous time intensive task fn run(&mut self); } +/// Abstraction for a FIFO task queue that will only queue up **one** `next` job. +/// It keeps overwriting the next job until it is actually taken to be processed #[derive(Debug, Clone)] pub struct AsyncSingleJob { next: Arc>>, @@ -70,7 +54,7 @@ impl false } - /// + /// take out last finished job pub fn take_last(&self) -> Option { if let Ok(mut last) = self.last.lock() { last.take() @@ -79,14 +63,13 @@ impl } } - /// + /// spawns `task` if nothing is running currently, otherwise schedules as `next` overwriting if `next` was set before pub fn spawn(&mut self, task: J) -> bool { self.schedule_next(task); self.check_for_job() } - /// - pub fn check_for_job(&self) -> bool { + fn check_for_job(&self) -> bool { if self.is_pending() { return false; } @@ -125,14 +108,12 @@ impl Ok(()) } - /// fn schedule_next(&mut self, task: J) { if let Ok(mut next) = self.next.lock() { *next = Some(task); } } - /// fn take_next(&self) -> Option { if let Ok(mut next) = self.next.lock() { next.take() diff --git a/asyncgit/src/error.rs b/asyncgit/src/error.rs index a22c9dbd..a113419a 100644 --- a/asyncgit/src/error.rs +++ b/asyncgit/src/error.rs @@ -50,3 +50,9 @@ impl From> for Error { Self::Generic(format!("poison error: {}", error)) } } + +impl From> for Error { + fn from(error: crossbeam_channel::SendError) -> Self { + Self::Generic(format!("send error: {}", error)) + } +} diff --git a/asyncgit/src/lib.rs b/asyncgit/src/lib.rs index a74042c5..dbee02b1 100644 --- a/asyncgit/src/lib.rs +++ b/asyncgit/src/lib.rs @@ -22,6 +22,7 @@ //TODO: get this in someday since expect still leads us to crashes sometimes // #![deny(clippy::expect_used)] +pub mod asyncjob; mod blame; pub mod cached; mod commit_files; diff --git a/src/components/syntax_text.rs b/src/components/syntax_text.rs index c13ff5e2..57946ac1 100644 --- a/src/components/syntax_text.rs +++ b/src/components/syntax_text.rs @@ -11,7 +11,7 @@ use crate::{ }, }; use anyhow::Result; -use async_utils::AsyncSingleJob; +use asyncgit::asyncjob::AsyncSingleJob; use asyncgit::{ sync::{self, TreeFile}, AsyncNotification, CWD, diff --git a/src/ui/syntax_text.rs b/src/ui/syntax_text.rs index dfdb3b93..9cd8ae9b 100644 --- a/src/ui/syntax_text.rs +++ b/src/ui/syntax_text.rs @@ -1,4 +1,4 @@ -use async_utils::AsyncJob; +use asyncgit::asyncjob::AsyncJob; use lazy_static::lazy_static; use scopetime::scope_time; use std::{