watch

Function watch 

Source
pub async fn watch(name: &str) -> Result<Receiver<Config>>
Expand description

Watch a configuration file for changes.

Returns a stream that yields new Config instances whenever the configuration file is modified on disk.

§Arguments

  • name - The base name of the configuration file (without path or extension)

§Returns

A receiver channel that yields Config instances when the file changes.

§Examples

use prefer::watch;

#[tokio::main]
async fn main() -> prefer::Result<()> {
    let mut receiver = watch("myapp").await?;

    while let Some(config) = receiver.recv().await {
        println!("Configuration updated!");
        let value: String = config.get("some.key")?;
    }

    Ok(())
}