Closed wvhulle closed 1 year ago
I have found the answer in https://github.com/notify-rs/notify/issues/ So the solution is to keep the watcher in scope? Is there any other cleaner solution?
cleaner solution
What do you mean with that ? If you drop the watcher, it will deconstruct its runtime. There are various options by which you could keep it alive for the duration of your application. My guess is that you're currently blocked by some specific idea of how the flow of your application looks like and can't see the solution.
System details
rustc --version
: rustc 1.75.0-nightly (0f44eb32f 2023-11-09)What you did (as detailed as you can)
I installed notify, added an file event listener to the directory and file
data/file.txt
. I put the event listener and attachment inside a helper function.What you expected
I expected updates to the file be shown when the file is written to.
What happened
The attachment of the watcher in the helper function does not work.
To reproduce:
cargo run --example main_bug
. This does not show the output from the handler.It only works if I plug the watch code inside the main function. Why can I not put the watch code in a helper function?
To test workaround
cargo run --example main_working
. This does show the output, but it is unclear to me why it is necessary to put thewatch
inside themain
.