mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-11-28 23:59:25 +00:00
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>
11 lines
461 B
Rust
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)
|
|
}
|