INNER CODE UNIT · Rust

merge

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

    pub fn merge(&self, other: &Config, namespace: &str) -> usize {
        // Snapshot `other` first (its read guard is released at the end of this statement) so that
        // acquiring our own write lock can never overlap with it - safe even if `other` is a clone
        // of `self`.
        let entries = other.0.read().snapshot();
        self.0.write().absorb(entries, namespace)
    }

    /// Returns the setting for the given key, falling back to the default, or `Ok(None)` when the
    /// key is unknown. See [`ConfigStore::get`].
    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.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…