Skip to content

Commit

Permalink
Replaced channel with notifu
Browse files Browse the repository at this point in the history
  • Loading branch information
agersant committed Oct 12, 2024
1 parent f955eb7 commit 8100dfc
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use log::{error, info};
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use notify_debouncer_full::{Debouncer, FileIdMap};
use regex::Regex;
use tokio::sync::{futures::Notified, mpsc::unbounded_channel, Notify, RwLock};
use tokio::sync::{futures::Notified, Notify, RwLock};

use crate::app::Error;

Expand Down Expand Up @@ -82,11 +82,13 @@ impl Manager {
pub async fn new(config_file_path: &Path, auth_secret: auth::Secret) -> Result<Self, Error> {
tokio::fs::File::create_new(config_file_path).await.ok();

let (sender, mut receiver) = unbounded_channel::<()>();
let mut debouncer =
notify_debouncer_full::new_debouncer(Duration::from_secs(1), None, move |_| {
sender.send(()).ok();
})?;
let notify = Arc::new(Notify::new());
let mut debouncer = notify_debouncer_full::new_debouncer(Duration::from_secs(1), None, {
let notify = notify.clone();
move |_| {
notify.notify_waiters();
}
})?;

debouncer
.watcher()
Expand All @@ -104,15 +106,11 @@ impl Manager {
let manager = manager.clone();
async move {
loop {
match receiver.recv().await {
None => break,
Some(_) => {
if let Err(e) = manager.reload_config().await {
error!("Configuration error: {e}");
} else {
info!("Sucessfully applied configuration change");
}
}
notify.notified().await;
if let Err(e) = manager.reload_config().await {
error!("Configuration error: {e}");
} else {
info!("Sucessfully applied configuration change");
}
}
}
Expand Down

0 comments on commit 8100dfc

Please sign in to comment.