From f67916952b864ff4e7fe87fd2aca85887cee5aad Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sun, 6 Dec 2026 15:40:33 +0800 Subject: [PATCH] docs(task): state the queue contract precisely The doc comments of apply, start and interval left open what a changed interval does to a running timer, which keys start accepts, and whether a running key still reports its interval. State the behaviour the code kept from the original scheduler. --- crates/clash-verge-task/src/timers.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/clash-verge-task/src/timers.rs b/crates/clash-verge-task/src/timers.rs index a52374f04..2bb6f0bd3 100644 --- a/crates/clash-verge-task/src/timers.rs +++ b/crates/clash-verge-task/src/timers.rs @@ -59,7 +59,8 @@ impl KeyedTimers { } /// Replaces the schedule. Timers that stay keep their next fire unless their interval - /// changed; a changed interval restarts from the new plan's `first_delay`. + /// changed: an idle timer then restarts from the new plan's `first_delay`, while one whose + /// run is in flight is re-armed with the new interval by `finish`. pub fn apply(&mut self, schedule: HashMap) -> Vec> { let Self { queue, tasks } = self; let mut changes = Vec::new(); @@ -128,6 +129,8 @@ impl KeyedTimers { } /// Marks the key running; `false` when the key is unknown or a run is already in flight. + /// Only a key that `next_expired` returned may be started: starting any other key forgets + /// its queue handle and leaves the entry armed. pub fn start(&mut self, key: &K) -> bool { let Some(state) = self.tasks.get_mut(key) else { return false; @@ -161,8 +164,8 @@ impl KeyedTimers { false } - /// The interval of a timer still scheduled to run; `None` for an unknown or retired key. - /// Takes any borrowed form of the key, so a `&str` lookup needs no owned key. + /// The interval of a timer that is not retired, running or not; `None` for an unknown or + /// retired key. Takes any borrowed form of the key, so a `&str` lookup needs no owned key. pub fn interval(&self, key: &Q) -> Option where K: Borrow,