From 90aa0a4e44d1097929e9575f3016fec0a32437b3 Mon Sep 17 00:00:00 2001 From: Yujia Qiao Date: Mon, 7 Feb 2022 18:12:13 +0800 Subject: [PATCH] fix: use unbounded channels in `config_watcher` (#127) --- src/config_watcher.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/config_watcher.rs b/src/config_watcher.rs index d269831b..f825d7fa 100644 --- a/src/config_watcher.rs +++ b/src/config_watcher.rs @@ -93,19 +93,17 @@ impl InstanceConfig for ClientConfig { } pub struct ConfigWatcherHandle { - pub event_rx: mpsc::Receiver, + pub event_rx: mpsc::UnboundedReceiver, } impl ConfigWatcherHandle { pub async fn new(path: &Path, shutdown_rx: broadcast::Receiver) -> Result { - let (event_tx, event_rx) = mpsc::channel(16); - + let (event_tx, event_rx) = mpsc::unbounded_channel(); let origin_cfg = Config::from_file(path).await?; // Initial start event_tx .send(ConfigChange::General(Box::new(origin_cfg.clone()))) - .await .unwrap(); tokio::spawn(config_watcher( @@ -124,7 +122,7 @@ impl ConfigWatcherHandle { async fn config_watcher( _path: PathBuf, mut shutdown_rx: broadcast::Receiver, - _event_tx: mpsc::Sender, + _event_tx: mpsc::UnboundedSender, _old: Config, ) -> Result<()> { // Do nothing except waiting for ctrl-c @@ -137,7 +135,7 @@ async fn config_watcher( async fn config_watcher( path: PathBuf, mut shutdown_rx: broadcast::Receiver, - event_tx: mpsc::Sender, + event_tx: mpsc::UnboundedSender, mut old: Config, ) -> Result<()> { let (fevent_tx, mut fevent_rx) = mpsc::channel(16); @@ -146,7 +144,7 @@ async fn config_watcher( notify::recommended_watcher(move |res: Result| match res { Ok(e) => { if let EventKind::Modify(ModifyKind::Data(_)) = e.kind { - let _ = fevent_tx.blocking_send(true); + let _ = fevent_tx.send(true); } } Err(e) => error!("watch error: {:#}", e), @@ -171,7 +169,7 @@ async fn config_watcher( }; for event in calculate_events(&old, &new) { - event_tx.send(event).await?; + event_tx.send(event)?; } old = new;