pub struct ConfigWatcher {
pub poll_interval_ms: u64,
/* private fields */
}Expand description
Configuration hot-reload watcher: polls the configuration center at a fixed interval and notifies subscribers when value changes are detected.
Since the current implementation is a pure in-memory model, the watcher detects changes by recording the last snapshot and comparing it with the current values. In real-world scenarios this can be replaced with long polling or the Watch API of Consul/Nacos.
Fields§
§poll_interval_ms: u64Polling interval (in milliseconds)
Implementations§
Source§impl ConfigWatcher
impl ConfigWatcher
pub fn new(poll_interval_ms: u64) -> Self
Sourcepub fn watch(&self, key: &str, callback: ConfigChangeCallback)
pub fn watch(&self, key: &str, callback: ConfigChangeCallback)
Register a change listener for a key
Sourcepub fn poll<C: ConfigCenter>(&self, center: &C) -> usize
pub fn poll<C: ConfigCenter>(&self, center: &C) -> usize
Perform a single poll: compare the current configuration with the last snapshot and trigger change callbacks. Returns the number of changes detected in this poll.
Sourcepub fn watcher_count(&self) -> usize
pub fn watcher_count(&self) -> usize
Returns the number of currently registered watchers
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ConfigWatcher
impl RefUnwindSafe for ConfigWatcher
impl Send for ConfigWatcher
impl Sync for ConfigWatcher
impl Unpin for ConfigWatcher
impl UnsafeUnpin for ConfigWatcher
impl UnwindSafe for ConfigWatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more