Specify delay for fs Poll mode

This commit is contained in:
Félix Saparelli 2021-08-24 22:28:29 +12:00
parent 33fb691d29
commit 6767948daa
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
1 changed files with 5 additions and 2 deletions

View File

@ -4,6 +4,8 @@ use std::{
collections::{HashMap, HashSet},
mem::take,
path::PathBuf,
sync::{Arc, Mutex},
time::Duration,
};
use notify::Watcher as _;
@ -23,7 +25,7 @@ use crate::{
#[non_exhaustive]
pub enum Watcher {
Native,
Poll,
Poll(Duration),
}
impl Default for Watcher {
@ -39,7 +41,8 @@ impl Watcher {
) -> Result<Box<dyn notify::Watcher + Send>, RuntimeError> {
match self {
Self::Native => notify::RecommendedWatcher::new(f).map(|w| Box::new(w) as _),
Self::Poll => notify::PollWatcher::new(f).map(|w| Box::new(w) as _),
Self::Poll(delay) => notify::PollWatcher::with_delay(Arc::new(Mutex::new(f)), delay)
.map(|w| Box::new(w) as _),
}
.map_err(|err| RuntimeError::FsWatcherCreate { kind: self, err })
}