Refactor directory size to allow for cancellation

This commit is contained in:
Jeremy Soller 2024-11-15 17:30:25 -07:00
parent 6c0c89e1f7
commit 2f08c05afe
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
3 changed files with 124 additions and 63 deletions

View file

@ -231,19 +231,22 @@ pub enum ControllerState {
Running,
}
#[derive(Debug)]
struct ControllerInner {
state: Mutex<ControllerState>,
condvar: Condvar,
}
#[derive(Clone)]
#[derive(Debug)]
pub struct Controller {
primary: bool,
inner: Arc<ControllerInner>,
}
impl Controller {
pub fn new() -> Self {
Self {
primary: true,
inner: Arc::new(ControllerInner {
state: Mutex::new(ControllerState::Running),
condvar: Condvar::new(),
@ -295,6 +298,24 @@ impl Controller {
}
}
impl Clone for Controller {
fn clone(&self) -> Self {
Self {
primary: false,
inner: self.inner.clone(),
}
}
}
impl Drop for Controller {
fn drop(&mut self) {
// Cancel operations if primary controller is dropped
if self.primary {
self.cancel();
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ReplaceResult {
Replace(bool),