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