fabro/lib/foundation/fabro-util/src/sync.rs
Bryan Helmkamp 1f6e53c949
Share one poison-tolerant lock helper from fabro-util
Seven crates' files each carried the same four-line lock function that
recovers a poisoned mutex. fabro_util::sync::lock is that function, once;
the copies in fabro-petri and fabro-server are gone. fabro-template's
helper panics on poison instead, a different policy, and is left as is.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-20 14:47:46 -04:00

11 lines
461 B
Rust

//! Locking helpers shared across crates.
use std::sync::{Mutex, MutexGuard, PoisonError};
/// Lock a mutex, recovering the guard when another holder panicked. The
/// state such a mutex guards is bookkeeping (a cache, a set of ids, a
/// counter) that stays usable after a panic elsewhere, so the poison is
/// cleared rather than propagated.
pub fn lock<T>(mutex: &Mutex<T>) -> MutexGuard<'_, T> {
mutex.lock().unwrap_or_else(PoisonError::into_inner)
}