Skip to content

Commit bfa83ae

Browse files
author
Stephan Dilly
committed
move async_job abstraction into asyncgit for now
1 parent 16f03d4 commit bfa83ae

File tree

11 files changed

+22
-91
lines changed

11 files changed

+22
-91
lines changed

Cargo.lock

-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ keywords = [
2020

2121
[dependencies]
2222
scopetime = { path = "./scopetime", version = "0.1" }
23-
asyncgit = { path = "./asyncgit" }
23+
asyncgit = { path = "./asyncgit", version = "0.16" }
2424
filetree = { path = "./filetree" }
25-
async_utils = { path = "./async_utils" }
2625
crossterm = { version = "0.19", features = [ "serde" ] }
2726
clap = { version = "2.33", default-features = false }
2827
tui = { version = "0.15", default-features = false, features = ['crossterm', 'serde'] }
@@ -67,7 +66,6 @@ timing=["scopetime/enabled"]
6766
members=[
6867
"asyncgit",
6968
"scopetime",
70-
"async_utils",
7169
"filetree",
7270
]
7371

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ fmt:
4545

4646
clippy:
4747
touch src/main.rs
48-
cargo clean -p gitui -p asyncgit -p scopetime -p filetree -p async_utils
48+
cargo clean -p gitui -p asyncgit -p scopetime -p filetree
4949
cargo clippy --workspace --all-features
5050

5151
clippy-nightly:
5252
touch src/main.rs
53-
cargo clean -p gitui -p asyncgit -p scopetime -p filetree -p async_utils
53+
cargo clean -p gitui -p asyncgit -p scopetime -p filetree
5454
cargo +nightly clippy --workspace --all-features
5555

5656
check: fmt clippy test

async_utils/Cargo.toml

-21
This file was deleted.

async_utils/LICENSE.md

-1
This file was deleted.

async_utils/src/error.rs

-21
This file was deleted.

async_utils/src/lib.rs asyncgit/src/asyncjob/mod.rs

+10-29
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
1-
// #![forbid(missing_docs)]
2-
#![deny(unsafe_code)]
3-
#![deny(
4-
unused_imports,
5-
unused_must_use,
6-
dead_code,
7-
unstable_name_collisions,
8-
unused_assignments
9-
)]
10-
#![deny(unstable_name_collisions)]
11-
#![deny(clippy::all, clippy::perf, clippy::nursery, clippy::pedantic)]
1+
//! provides `AsyncJob` trait and `AsyncSingleJob` struct
2+
123
#![deny(clippy::expect_used)]
13-
#![deny(clippy::filetype_is_file)]
14-
#![deny(clippy::cargo)]
15-
#![deny(clippy::unwrap_used)]
16-
#![deny(clippy::panic)]
17-
#![deny(clippy::match_like_matches_macro)]
18-
#![deny(clippy::needless_update)]
19-
#![allow(clippy::module_name_repetitions)]
20-
#![allow(clippy::must_use_candidate)]
21-
#![allow(clippy::missing_errors_doc)]
22-
23-
mod error;
244

5+
use crate::error::Result;
256
use crossbeam_channel::Sender;
26-
use error::Result;
277
use std::sync::{Arc, Mutex};
288

9+
/// trait that defines an async task we can run on a threadpool
2910
pub trait AsyncJob: Send + Sync + Clone {
11+
/// can run a synchronous time intensive task
3012
fn run(&mut self);
3113
}
3214

15+
/// Abstraction for a FIFO task queue that will only queue up **one** `next` job.
16+
/// It keeps overwriting the next job until it is actually taken to be processed
3317
#[derive(Debug, Clone)]
3418
pub struct AsyncSingleJob<J: AsyncJob, T: Copy + Send + 'static> {
3519
next: Arc<Mutex<Option<J>>>,
@@ -70,7 +54,7 @@ impl<J: 'static + AsyncJob, T: Copy + Send + 'static>
7054
false
7155
}
7256

73-
///
57+
/// take out last finished job
7458
pub fn take_last(&self) -> Option<J> {
7559
if let Ok(mut last) = self.last.lock() {
7660
last.take()
@@ -79,14 +63,13 @@ impl<J: 'static + AsyncJob, T: Copy + Send + 'static>
7963
}
8064
}
8165

82-
///
66+
/// spawns `task` if nothing is running currently, otherwise schedules as `next` overwriting if `next` was set before
8367
pub fn spawn(&mut self, task: J) -> bool {
8468
self.schedule_next(task);
8569
self.check_for_job()
8670
}
8771

88-
///
89-
pub fn check_for_job(&self) -> bool {
72+
fn check_for_job(&self) -> bool {
9073
if self.is_pending() {
9174
return false;
9275
}
@@ -125,14 +108,12 @@ impl<J: 'static + AsyncJob, T: Copy + Send + 'static>
125108
Ok(())
126109
}
127110

128-
///
129111
fn schedule_next(&mut self, task: J) {
130112
if let Ok(mut next) = self.next.lock() {
131113
*next = Some(task);
132114
}
133115
}
134116

135-
///
136117
fn take_next(&self) -> Option<J> {
137118
if let Ok(mut next) = self.next.lock() {
138119
next.take()

asyncgit/src/error.rs

+6
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ impl<T> From<std::sync::PoisonError<T>> for Error {
5050
Self::Generic(format!("poison error: {}", error))
5151
}
5252
}
53+
54+
impl<T> From<crossbeam_channel::SendError<T>> for Error {
55+
fn from(error: crossbeam_channel::SendError<T>) -> Self {
56+
Self::Generic(format!("send error: {}", error))
57+
}
58+
}

asyncgit/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//TODO: get this in someday since expect still leads us to crashes sometimes
2323
// #![deny(clippy::expect_used)]
2424

25+
pub mod asyncjob;
2526
mod blame;
2627
pub mod cached;
2728
mod commit_files;

src/components/syntax_text.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
},
1212
};
1313
use anyhow::Result;
14-
use async_utils::AsyncSingleJob;
14+
use asyncgit::asyncjob::AsyncSingleJob;
1515
use asyncgit::{
1616
sync::{self, TreeFile},
1717
AsyncNotification, CWD,

src/ui/syntax_text.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use async_utils::AsyncJob;
1+
use asyncgit::asyncjob::AsyncJob;
22
use lazy_static::lazy_static;
33
use scopetime::scope_time;
44
use std::{

0 commit comments

Comments
 (0)