pub struct AsyncMutex<T> { /* private fields */ }Expand description
An async mutex lock that can be used in async functions to prevent blocking current execution while waiting for the
lock to become available. So for this to work the lock() method does not return a MutexGuard immediately but a
Future that will resove into a AsyncMutexGuard when awaited.
Implementations§
Source§impl<T> AsyncMutex<T>
impl<T> AsyncMutex<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Create the AsyncMutex
Sourcepub async fn lock(&self) -> AsyncMutexGuard<'_, T>
pub async fn lock(&self) -> AsyncMutexGuard<'_, T>
Locking the data secured by the AsyncMutex will yield a Future that must be awaited to actually acquire
the lock.
Sourcepub fn into_inner(self) -> Result<T, Self>where
T: Sized,
pub fn into_inner(self) -> Result<T, Self>where
T: Sized,
Provide the inner data wrapped by this AsyncMutex. This will only provide the contained data if there is only
one active reference to it. If the data is still shared more than once, eg. because there are active Futures
awaiting a lock this will return the actual AsyncMutex in the Err variant.
Auto Trait Implementations§
impl<T> Freeze for AsyncMutex<T>
impl<T> !RefUnwindSafe for AsyncMutex<T>
impl<T> Send for AsyncMutex<T>where
T: Send,
impl<T> Sync for AsyncMutex<T>where
T: Send,
impl<T> Unpin for AsyncMutex<T>
impl<T> !UnwindSafe for AsyncMutex<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