Implement cancel_all
This commit is contained in:
parent
43f1e59516
commit
ccfd130022
@ -7,7 +7,7 @@ use std::{
|
|||||||
atomic::{AtomicI32, Ordering},
|
atomic::{AtomicI32, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
},
|
},
|
||||||
time::Duration,
|
time::Duration, mem::swap,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
@ -38,6 +38,7 @@ enum RunnerMsg {
|
|||||||
Quit,
|
Quit,
|
||||||
QueueRun(RunHandle, SectionRef, Duration),
|
QueueRun(RunHandle, SectionRef, Duration),
|
||||||
CancelRun(RunHandle),
|
CancelRun(RunHandle),
|
||||||
|
CancelAll,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -170,6 +171,14 @@ async fn runner_task(
|
|||||||
trace!(handle = handle.0, "cancelling run by handle");
|
trace!(handle = handle.0, "cancelling run by handle");
|
||||||
run.cancel(&*interface);
|
run.cancel(&*interface);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
CancelAll => {
|
||||||
|
let mut old_runs = LinkedList::new();
|
||||||
|
swap(&mut old_runs, &mut run_queue);
|
||||||
|
trace!(count = old_runs.len(), "cancelling all runs");
|
||||||
|
for mut run in old_runs {
|
||||||
|
run.cancel(&*interface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -235,7 +244,8 @@ impl SectionRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cancel_all(&mut self) -> Result<()> {
|
pub async fn cancel_all(&mut self) -> Result<()> {
|
||||||
todo!()
|
self.msg_send.send(RunnerMsg::CancelAll).await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn pause(&mut self) -> Result<()> {
|
pub async fn pause(&mut self) -> Result<()> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user