mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-06 23:00:15 +08:00
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.
This commit is contained in:
@@ -59,7 +59,8 @@ impl<K: Eq + Hash + Clone> KeyedTimers<K> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Replaces the schedule. Timers that stay keep their next fire unless their interval
|
/// 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<K, TimerPlan>) -> Vec<TimerChange<K>> {
|
pub fn apply(&mut self, schedule: HashMap<K, TimerPlan>) -> Vec<TimerChange<K>> {
|
||||||
let Self { queue, tasks } = self;
|
let Self { queue, tasks } = self;
|
||||||
let mut changes = Vec::new();
|
let mut changes = Vec::new();
|
||||||
@@ -128,6 +129,8 @@ impl<K: Eq + Hash + Clone> KeyedTimers<K> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Marks the key running; `false` when the key is unknown or a run is already in flight.
|
/// 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 {
|
pub fn start(&mut self, key: &K) -> bool {
|
||||||
let Some(state) = self.tasks.get_mut(key) else {
|
let Some(state) = self.tasks.get_mut(key) else {
|
||||||
return false;
|
return false;
|
||||||
@@ -161,8 +164,8 @@ impl<K: Eq + Hash + Clone> KeyedTimers<K> {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The interval of a timer still scheduled to run; `None` for an unknown or retired key.
|
/// The interval of a timer that is not retired, running or not; `None` for an unknown or
|
||||||
/// Takes any borrowed form of the key, so a `&str` lookup needs no owned key.
|
/// retired key. Takes any borrowed form of the key, so a `&str` lookup needs no owned key.
|
||||||
pub fn interval<Q>(&self, key: &Q) -> Option<Duration>
|
pub fn interval<Q>(&self, key: &Q) -> Option<Duration>
|
||||||
where
|
where
|
||||||
K: Borrow<Q>,
|
K: Borrow<Q>,
|
||||||
|
|||||||
Reference in New Issue
Block a user