pub struct MutexWithTimeout<T> { /* private fields */ }
Expand description
A wrapper around std::sync::Mutex
that allows for a timeout to be set.
Implementations§
Source§impl<T> MutexWithTimeout<T>
impl<T> MutexWithTimeout<T>
Sourcepub fn new_with_timeout(inner: T, timeout: Duration) -> Self
pub fn new_with_timeout(inner: T, timeout: Duration) -> Self
Creates a new MutexWithTimeout
with the given timeout.
Sourcepub fn lock(&self) -> Option<MutexGuard<'_, T>>
pub fn lock(&self) -> Option<MutexGuard<'_, T>>
Will attempt to lock the inner std::sync::Mutex
.
If the lock is not acquired within the timeout, None
will be returned.
Sourcepub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
Calls the inner mutex’s try_lock
method.
Auto Trait Implementations§
impl<T> !Freeze for MutexWithTimeout<T>
impl<T> RefUnwindSafe for MutexWithTimeout<T>
impl<T> Send for MutexWithTimeout<T>where
T: Send,
impl<T> Sync for MutexWithTimeout<T>where
T: Send,
impl<T> Unpin for MutexWithTimeout<T>where
T: Unpin,
impl<T> UnwindSafe for MutexWithTimeout<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more