mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-22 02:12:58 +03:00
move async_job abstraction into asyncgit
for now
This commit is contained in:
parent
16f03d459e
commit
bfa83ae343
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -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",
|
||||
|
@ -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",
|
||||
]
|
||||
|
||||
|
4
Makefile
4
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
|
||||
|
@ -1,21 +0,0 @@
|
||||
[package]
|
||||
name = "async_utils"
|
||||
version = "0.1.0"
|
||||
authors = ["Stephan Dilly <dilly.stephan@gmail.com>"]
|
||||
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"
|
@ -1 +0,0 @@
|
||||
../LICENSE.md
|
@ -1,21 +0,0 @@
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("`{0}`")]
|
||||
Generic(String),
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
impl<T> From<crossbeam_channel::SendError<T>> for Error {
|
||||
fn from(error: crossbeam_channel::SendError<T>) -> Self {
|
||||
Self::Generic(format!("send error: {}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<std::sync::PoisonError<T>> for Error {
|
||||
fn from(error: std::sync::PoisonError<T>) -> Self {
|
||||
Self::Generic(format!("poison error: {}", error))
|
||||
}
|
||||
}
|
@ -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<J: AsyncJob, T: Copy + Send + 'static> {
|
||||
next: Arc<Mutex<Option<J>>>,
|
||||
@ -70,7 +54,7 @@ impl<J: 'static + AsyncJob, T: Copy + Send + 'static>
|
||||
false
|
||||
}
|
||||
|
||||
///
|
||||
/// take out last finished job
|
||||
pub fn take_last(&self) -> Option<J> {
|
||||
if let Ok(mut last) = self.last.lock() {
|
||||
last.take()
|
||||
@ -79,14 +63,13 @@ impl<J: 'static + AsyncJob, T: Copy + Send + 'static>
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// 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<J: 'static + AsyncJob, T: Copy + Send + 'static>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
fn schedule_next(&mut self, task: J) {
|
||||
if let Ok(mut next) = self.next.lock() {
|
||||
*next = Some(task);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
fn take_next(&self) -> Option<J> {
|
||||
if let Ok(mut next) = self.next.lock() {
|
||||
next.take()
|
@ -50,3 +50,9 @@ impl<T> From<std::sync::PoisonError<T>> for Error {
|
||||
Self::Generic(format!("poison error: {}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<crossbeam_channel::SendError<T>> for Error {
|
||||
fn from(error: crossbeam_channel::SendError<T>) -> Self {
|
||||
Self::Generic(format!("send error: {}", error))
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -11,7 +11,7 @@ use crate::{
|
||||
},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use async_utils::AsyncSingleJob;
|
||||
use asyncgit::asyncjob::AsyncSingleJob;
|
||||
use asyncgit::{
|
||||
sync::{self, TreeFile},
|
||||
AsyncNotification, CWD,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use async_utils::AsyncJob;
|
||||
use asyncgit::asyncjob::AsyncJob;
|
||||
use lazy_static::lazy_static;
|
||||
use scopetime::scope_time;
|
||||
use std::{
|
||||
|
Loading…
Reference in New Issue
Block a user