notify-rs / notify

🔭 Cross-platform filesystem notification library for Rust.
https://docs.rs/notify
2.76k stars 222 forks source link

Simple example from documentation doesn't work #576

Open osenvosem opened 8 months ago

osenvosem commented 8 months ago

MacOS 13.6, notify 6.1.1

The code executed inside a sync main function. Nothing happens, no errors or output in console when creating/changing/deleting files in the watched folder.

Value of the sync_dir variable is "/Users/srg/conf_sync"

    let mut watcher = notify::recommended_watcher(|res| match res {
        Ok(event) => println!("event {:?}", event),
        Err(err) => println!("error {:?}", err),
    })
    .expect("Error creating watcher");

    watcher
        .watch(Path::new(&sync_dir), RecursiveMode::Recursive)
        .expect("Error start watcher");
vitali2y commented 5 months ago

Linux Mint 21.2, notify 6.1.1: simple example just exits with 0 exit code, nothing happens.

dsincl12 commented 2 months ago

Add use std::thread; and then the following lines before Ok(()):

println!("Watcher is running. Press Ctrl+C to exit.");

thread::park();