pub struct AsyncRWLock<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 WriteGuard immediately but a
Future that will resolve into a AsyncWriteLockGuard when awaited.
In the same way the read method will return a Future resolving to an AsyncReadLockGuard when awaited.
Implementations§
Source§impl<T> AsyncRWLock<T>
impl<T> AsyncRWLock<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Create the AsyncRWLock
Sourcepub async fn write(&self) -> AsyncWriteLockGuard<'_, T>
pub async fn write(&self) -> AsyncWriteLockGuard<'_, T>
Locking the data for write access secured by the AsyncRWLock will yield a Future that must be awaited to
actually acquire the lock.
pub fn write_blocking(&self) -> WriteLockGuard<'_, T>
Sourcepub async fn read(&self) -> AsyncReadLockGuard<'_, T>
pub async fn read(&self) -> AsyncReadLockGuard<'_, T>
Locking the data for read access secured by the AsyncRWLock will yield a Future that must be awaited to
actually acquire the lock.
Sourcepub fn into_inner(self) -> Result<T, Self>
pub fn into_inner(self) -> Result<T, Self>
Provide the inner data wrapped by this AsyncRWLock. 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 AsyncRWLock in the Err variant.