From 51e1110ca0f7253fc1d97e82a8e058d9bef93899 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 3 Sep 2023 00:34:23 +0800 Subject: [PATCH] fix: wrong resetting of the cursor after the task canceled --- core/src/tasks/tasks.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/tasks/tasks.rs b/core/src/tasks/tasks.rs index 8bb6e7bf..6c541865 100644 --- a/core/src/tasks/tasks.rs +++ b/core/src/tasks/tasks.rs @@ -121,12 +121,12 @@ impl Tasks { } pub fn cancel(&mut self) -> bool { - let id = self.scheduler.running.read().get_id(self.cursor); - if !id.map(|id| self.scheduler.cancel(id)).unwrap_or(false) { + let running = self.scheduler.running.read(); + if !running.get_id(self.cursor).map(|id| self.scheduler.cancel(id)).unwrap_or(false) { return false; } - self.next(); + self.cursor = self.cursor.min(running.len().saturating_sub(1)); true }