Struct anycache::FromWatchedFile
source · pub struct FromWatchedFile<T> { /* private fields */ }Expand description
FromWatchedFile is a struct that reads a file and watches for changes to the file. When the file changes, the struct will reload the file and update the value in the background. This struct is useful for reloading configuration files or other files that are read frequently. It is thread safe. Note: Each FromWatchedFile spawns a new thread to watch the file do not use too many of them!
Implementations§
source§impl<T> FromWatchedFile<T>
impl<T> FromWatchedFile<T>
sourcepub fn new<F>(file_path: &str, parser: F, interval: Duration) -> Self
pub fn new<F>(file_path: &str, parser: F, interval: Duration) -> Self
Create a new FromWatchedFile struct and spawn a new thread with given interval and converter function. Converter function converts a slice of bytes to the desired type.
The file will be check based on interval. On change detected, the parser will be used to convert the file content to desired type.
You can get the latest copy using the get method.
Upon initialization, the first copy will be constructed.
The code never fails. If the file gone missing, or the file is not readable, the value will be None.