Browse Source

Implement cancel_all

drone-volume-cache
Alex Mikhalev 4 years ago
parent
commit
ccfd130022
  1. 14
      src/section_runner.rs

14
src/section_runner.rs

@ -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…
Cancel
Save