Refactor directory size to allow for cancellation
This commit is contained in:
parent
6c0c89e1f7
commit
2f08c05afe
3 changed files with 124 additions and 63 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue