msg_tool\ext/
mutex.rs

1//! Extension for [std::sync::Mutex].
2pub trait MutexExt<T> {
3    /// Lock the mutex, blocking the current thread until it can be acquired.
4    fn lock_blocking(&self) -> std::sync::MutexGuard<'_, T>;
5}
6
7impl<T> MutexExt<T> for std::sync::Mutex<T> {
8    fn lock_blocking(&self) -> std::sync::MutexGuard<'_, T> {
9        self.lock().unwrap_or_else(|err| err.into_inner())
10    }
11}