INNER CODE UNIT · Rust

get

gosub-io/gosub-engine · crates/gosub_config/src/lib.rs:110

    pub fn get(&self, key: &str) -> Result<Option<Setting>> {
        self.0.read().get(key)
    }

    /// Sets a setting, persisting it and notifying any matching subscribers when the value changes.
    pub fn set(&self, key: &str, value: Setting) -> Result<()> {
        // Mutate under the lock, collect the callbacks to fire, then release the lock *before*
        // invoking them so callbacks can freely re-enter the store.
        let fire = {
            let store = self.0.write();
            store.set(key, value)?.map(|value| {
                let callbacks = store.matching_callbacks(key);
                (value, callbacks)
            })
        };
        if let Some((value, callbacks)) = fire {
            for callback in callbacks {
                callback(key, &value);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…