watch
Watches a configuration file for changes and invokes onReload with the freshly loaded configuration whenever the file is modified.
If a watcher already exists for the given file, the previous watcher is stopped and replaced. The returned FileWatcher is started automatically.
The reload callback is debounced (default 500ms) to avoid redundant reloads during rapid successive writes. Errors during reload are caught and printed to the configured output stream.
Example:
val watcher = YamlConfigManager.watch(configFile, ServerConfig::class) { config ->
println("Config reloaded: port=${config.port}")
}
// Later, to stop:
watcher.stop()Return
The started FileWatcher instance.
Since
1.0
Parameters
The configuration data class type.
The YAML file to watch.
The KClass of the configuration type.
Callback invoked with the reloaded configuration instance.
See also
Watches a configuration file for changes and invokes onReload with the freshly loaded configuration whenever the file is modified.
This is a convenience overload that infers the KClass from the reified type parameter.
Example:
YamlConfigManager.watch<ServerConfig>(configFile) { config ->
println("Config reloaded: port=${config.port}")
}Return
The started FileWatcher instance.
Since
1.0
Parameters
The configuration data class type.
The YAML file to watch.
Callback invoked with the reloaded configuration instance.