pub struct ConfigWatcher {
pub poll_interval_ms: u64,
/* private fields */
}Expand description
配置热更新监听器:以固定间隔轮询配置中心,检测到值变更时通知订阅者
由于当前实现为纯内存模型,Watch 通过记录上次快照并与当前值比较来检测变更。 在真实场景中可替换为 Consul/Nacos 的长轮询或 Watch API。
Fields§
§poll_interval_ms: u64轮询间隔(毫秒)
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)
注册一个 key 的变更监听
Sourcepub fn poll<C: ConfigCenter>(&self, center: &C) -> usize
pub fn poll<C: ConfigCenter>(&self, center: &C) -> usize
执行一次轮询检测:比较当前配置与上次快照,触发变更回调 返回本次检测到的变更数量
Sourcepub fn watcher_count(&self) -> usize
pub fn watcher_count(&self) -> usize
返回当前注册的 watcher 数量
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