Use RwLock::read in SyncStorage (#2463)

Replaces `RwLock::try_read` with `RwLock::read` in `SyncStorage`. This change prioritizes potential deadlocks over panics, as unwrapping a failed `try_read` is deemed less desirable.
This commit is contained in:
Rafał Krzyważnia authored and GitHub committed 2024-05-30 07:05:20 -05:00
1 parent 7d529cf39c
commit 54dbe6d074
1 file changed
+1 -9
+1 -9
View File
@@ -112,15 +112,7 @@ impl<T: Sync + Send + 'static> Storage<T> for SyncStorage {
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
at: crate::GenerationalRefBorrowInfo,
) -> Result<Self::Ref<'static, T>, error::BorrowError> {
let read = self.0.try_read();
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
let read = read.ok_or_else(|| at.borrowed_from.borrow_error())?;
#[cfg(not(any(debug_assertions, feature = "debug_ownership")))]
let read = read.ok_or_else(|| {
error::BorrowError::AlreadyBorrowedMut(error::AlreadyBorrowedMutError {})
})?;
let read = self.0.read();
RwLockReadGuard::try_map(read, |any| any.as_ref()?.downcast_ref())
.map_err(|_| {