fix: doesn't unlock before the task cancellation

This commit is contained in:
sxyazi 2023-09-08 06:39:35 +08:00
parent e412478043
commit d702cbcf9a
No known key found for this signature in database

View file

@ -121,12 +121,13 @@ impl Tasks {
} }
pub fn cancel(&mut self) -> bool { pub fn cancel(&mut self) -> bool {
let running = self.scheduler.running.read(); let id = self.scheduler.running.read().get_id(self.cursor);
if !running.get_id(self.cursor).map(|id| self.scheduler.cancel(id)).unwrap_or(false) { if id.map(|id| self.scheduler.cancel(id)) != Some(true) {
return false; return false;
} }
self.cursor = self.cursor.min(running.len().saturating_sub(1)); let len = self.scheduler.running.read().len();
self.cursor = self.cursor.min(len.saturating_sub(1));
true true
} }