Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PollWatcher: unify signature of new and with_delay #360

Merged
merged 1 commit into from Sep 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/poll.rs
Expand Up @@ -43,13 +43,10 @@ fn emit_event(event_handler: &Mutex<dyn EventHandler>, res: Result<Event>) {
}

impl PollWatcher {
/// Create a [PollWatcher] which polls every `delay` milliseconds
pub fn with_delay(
event_handler: Arc<Mutex<dyn EventHandler>>,
delay: Duration,
) -> Result<PollWatcher> {
/// Create a new [PollWatcher] and set the poll frequency to `delay`.
pub fn with_delay<F: EventHandler>(event_handler: F, delay: Duration) -> Result<PollWatcher> {
let mut p = PollWatcher {
event_handler,
event_handler: Arc::new(Mutex::new(event_handler)),
watches: Arc::new(Mutex::new(HashMap::new())),
open: Arc::new(AtomicBool::new(true)),
delay,
Expand Down Expand Up @@ -276,8 +273,10 @@ impl PollWatcher {

impl Watcher for PollWatcher {
/// Create a new [PollWatcher].
///
/// The default poll frequency is 30 seconds.
/// Use [with_delay] to manually set the poll frequency.
fn new<F: EventHandler>(event_handler: F) -> Result<Self> {
let event_handler = Arc::new(Mutex::new(event_handler));
let delay = Duration::from_secs(30);
Self::with_delay(event_handler, delay)
}
Expand Down