Struct hotwatch::blocking::Hotwatch [−][src]
pub struct Hotwatch { /* fields omitted */ }
Expand description
A blocking hotwatch instance.
No watching will actually happen until you call Hotwatch::run
, which blocks
the thread until a handler returns Flow::Exit
. This is useful if you just
want to wait on some criteria, rather than if you’re building some long-running
sexy hot reload service.
Dropping this will unwatch everything.
Implementations
Using Hotwatch::new
will give you a default delay of 2 seconds.
This method allows you to specify your own value.
Notes
A delay of over 30 seconds will prevent repetitions of previous events on macOS.
Watch a path and register a handler to it.
Handlers won’t actually be run until you call Hotwatch::run
.
When watching a directory, that handler will receive all events for all directory contents, even recursing through subdirectories.
Only the most specific applicable handler will be called. In other words, if you’re
watching “dir” and “dir/file1”, then only the latter handler will fire for changes to
file1
.
Errors
Watching will fail if the path can’t be read, returning Error::Io
.
Examples
use hotwatch::{blocking::{Flow, Hotwatch}, Event};
let mut hotwatch = Hotwatch::new().expect("hotwatch failed to initialize!");
// Note that this won't actually do anything until you call `hotwatch.run()`!
hotwatch.watch("README.md", |event: Event| {
if let Event::Write(path) = event {
println!("{:?} changed!", path);
Flow::Exit
} else {
Flow::Continue
}
}).expect("failed to watch file!");
Stop watching a path.
Errors
This will fail if the path wasn’t being watched, or if the path couldn’t be unwatched for some platform-specific internal reason.
Run handlers in an endless loop, blocking the thread.
The loop will only exit if a handler returns Flow::Exit
.