Skip to content

Commit 12cef5f

Browse files
author
Stephan Dilly
committed
also use status fetching for spinner state
1 parent f502c81 commit 12cef5f

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

asyncgit/src/status.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use crossbeam_channel::Sender;
33
use log::trace;
44
use std::{
55
hash::Hash,
6-
sync::{Arc, Mutex},
6+
sync::{
7+
atomic::{AtomicUsize, Ordering},
8+
Arc, Mutex,
9+
},
710
};
811
use sync::status::StatusType;
912

@@ -20,6 +23,7 @@ pub struct AsyncStatus {
2023
current: Arc<Mutex<Request<u64, Status>>>,
2124
last: Arc<Mutex<Status>>,
2225
sender: Sender<AsyncNotification>,
26+
pending: Arc<AtomicUsize>,
2327
}
2428

2529
impl AsyncStatus {
@@ -29,6 +33,7 @@ impl AsyncStatus {
2933
current: Arc::new(Mutex::new(Request(0, None))),
3034
last: Arc::new(Mutex::new(Status::default())),
3135
sender,
36+
pending: Arc::new(AtomicUsize::new(0)),
3237
}
3338
}
3439

@@ -38,6 +43,11 @@ impl AsyncStatus {
3843
last.clone()
3944
}
4045

46+
///
47+
pub fn is_pending(&self) -> bool {
48+
self.pending.load(Ordering::Relaxed) > 0
49+
}
50+
4151
///
4252
pub fn fetch(&mut self, request: u64) -> Option<Status> {
4353
let hash_request = hash(&request);
@@ -58,7 +68,10 @@ impl AsyncStatus {
5868
let arc_current = Arc::clone(&self.current);
5969
let arc_last = Arc::clone(&self.last);
6070
let sender = self.sender.clone();
71+
let arc_pending = Arc::clone(&self.pending);
6172
rayon_core::spawn(move || {
73+
arc_pending.fetch_add(1, Ordering::Relaxed);
74+
6275
let res = Self::get_status();
6376
trace!("status fetched: {}", hash(&res));
6477

@@ -74,6 +87,8 @@ impl AsyncStatus {
7487
*last = res;
7588
}
7689

90+
arc_pending.fetch_sub(1, Ordering::Relaxed);
91+
7792
sender
7893
.send(AsyncNotification::Status)
7994
.expect("error sending status");

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl App {
231231

232232
///
233233
pub fn any_work_pending(&self) -> bool {
234-
self.git_diff.is_pending()
234+
self.git_diff.is_pending() || self.git_status.is_pending()
235235
}
236236
}
237237

src/spinner.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ pub struct Spinner {
1010
}
1111

1212
impl Spinner {
13-
///
13+
/// increment spinner graphic by one
1414
pub fn update(&mut self) {
1515
self.idx += 1;
1616
self.idx %= SPINNER_CHARS.len();
1717
}
1818

19+
/// draws or removes spinner char depending on `pending` state
1920
pub fn draw<B: Backend>(
2021
&self,
2122
terminal: &mut Terminal<B>,

0 commit comments

Comments
 (0)