Skip to content

Commit

Permalink
shorten qualified paths
Browse files Browse the repository at this point in the history
  • Loading branch information
shouya committed Mar 14, 2024
1 parent fea4453 commit d82fbb1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/server/watcher.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use std::path::{Path, PathBuf};

use tokio::sync::mpsc::{self, Receiver, Sender};
use std::{
path::{Path, PathBuf},
time::Duration,
};

use tokio::{
sync::mpsc::{self, Receiver, Sender},
time::sleep,
};
use tracing::{error, warn};

use crate::util::{ConfigError, Result};
Expand All @@ -21,7 +27,7 @@ impl Watcher {

// sometimes the editor may touch the file multiple times in quick
// succession when saving, so we debounce the events
let rx = debounce(std::time::Duration::from_millis(500), rx);
let rx = debounce(Duration::from_millis(500), rx);

Ok(Self {
path: path.to_owned(),
Expand Down Expand Up @@ -88,7 +94,7 @@ impl Watcher {
"{} does not exist, waiting for it to be created",
self.path.display()
);
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
sleep(Duration::from_secs(10)).await;
}

watcher
Expand All @@ -104,7 +110,7 @@ impl Watcher {
}

fn debounce<T: Send + 'static>(
duration: std::time::Duration,
duration: Duration,
mut rx: Receiver<T>,
) -> Receiver<T> {
let (debounced_tx, debounced_rx) = mpsc::channel(1);
Expand All @@ -115,7 +121,7 @@ fn debounce<T: Send + 'static>(
val = rx.recv() => {
last = val;
}
_ = tokio::time::sleep(duration) => {
_ = sleep(duration) => {
if let Some(val) = last.take() {
debounced_tx.send(val).await.unwrap();
}
Expand Down

0 comments on commit d82fbb1

Please sign in to comment.