pub fn spawn(
key: TypeId,
name: &'static str,
spec: LoadSpec<'static>,
debounce: Duration,
reload: impl Fn() -> Result<Option<String>, Error> + Send + 'static,
) -> Result<WatchHandle>watch only.Expand description
Starts a background thread that runs reload whenever one of files changes.
Calling this twice for the same type is an error (AlreadyExists): a
second handle could only mislead, and the first watcher keeps running.
reload is expected to swap in a new snapshot. Returning Some(summary)
replaces the generic “reloaded” line with something more specific — which is
how diff reports the keys that moved without logging twice.
Its error is reported and discarded — an invalid or half-written file must degrade to “no change”, never to a crash, because the previous snapshot is still perfectly good.
The watch is registered before this function returns, so an edit that lands immediately afterwards cannot slip through the gap. Registering it on the background thread instead would leave a window — short, but reliably hit by anything that writes configuration during startup.
§Errors
If the notification backend cannot be created, if none of the directories
holding files can be watched, or if the thread cannot be spawned. A
directory that fails while others succeed is reported and skipped.