Async cleanup
This commit is contained in:
parent
d53681b6c0
commit
090ca387ab
1 changed files with 10 additions and 8 deletions
|
@ -1,14 +1,14 @@
|
|||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::{mpsc::channel, Arc},
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use log::{error, info};
|
||||
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
|
||||
use notify_debouncer_full::{DebounceEventResult, Debouncer, FileIdMap};
|
||||
use notify_debouncer_full::{Debouncer, FileIdMap};
|
||||
use regex::Regex;
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::sync::{mpsc::unbounded_channel, RwLock};
|
||||
|
||||
use crate::app::Error;
|
||||
|
||||
|
@ -81,9 +81,11 @@ 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, receiver) = channel::<DebounceEventResult>();
|
||||
let (sender, mut receiver) = unbounded_channel::<()>();
|
||||
let mut debouncer =
|
||||
notify_debouncer_full::new_debouncer(Duration::from_secs(1), None, sender)?;
|
||||
notify_debouncer_full::new_debouncer(Duration::from_secs(1), None, move |_| {
|
||||
sender.send(()).ok();
|
||||
})?;
|
||||
|
||||
debouncer
|
||||
.watcher()
|
||||
|
@ -100,9 +102,9 @@ impl Manager {
|
|||
let manager = manager.clone();
|
||||
async move {
|
||||
loop {
|
||||
match receiver.recv() {
|
||||
Err(_) => break,
|
||||
Ok(_) => {
|
||||
match receiver.recv().await {
|
||||
None => break,
|
||||
Some(_) => {
|
||||
if let Err(e) = manager.reload_config().await {
|
||||
error!("Configuration error: {e}");
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue