Skip to main content

watch_blocking

Function watch_blocking 

Source
pub fn watch_blocking<F>(watcher: &mut FileWatcher, callback: F)
where F: FnMut(&[PathBuf]) -> bool,
Expand description

Polls for file changes in a blocking loop, invoking callback with changed paths.

The loop is bounded by MAX_WATCH_ITERATIONS to prevent runaway execution. Returns when the callback returns false or the iteration limit is reached.

ยงExamples

use ssg::watch::{FileWatcher, WatchConfig, watch_blocking};
use std::time::Duration;
use tempfile::tempdir;

let dir = tempdir().unwrap();
let cfg = WatchConfig::new(dir.path().to_path_buf(), Duration::from_millis(1));
let mut watcher = FileWatcher::new(cfg).unwrap();
// Stop on the first callback invocation so the doctest terminates.
std::fs::write(dir.path().join("a.md"), "hi").unwrap();
watch_blocking(&mut watcher, |_changes| false);