pub struct Mutex<T> { /* private fields */ }Expand description
An async mutex
Locks will be acquired in the order they are requested
§Examples
let mutex = Rc::new(Mutex::new(0));
screeps_async::spawn(async move {
let mut val = mutex.lock().await;
*val = 1;
}).detach();Implementations§
Source§impl<T> Mutex<T>
impl<T> Mutex<T>
Sourcepub fn new(val: T) -> Self
pub fn new(val: T) -> Self
Construct a new Mutex in the unlocked state wrapping the given value
Sourcepub fn lock(&self) -> MutexLockFuture<'_, T> ⓘ
pub fn lock(&self) -> MutexLockFuture<'_, T> ⓘ
Acquire the mutex.
Returns a guard that release the mutex when dropped
Sourcepub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
Try to acquire the mutex.
If the mutex could not be acquired at this time return None, otherwise
returns a guard that will release the mutex when dropped.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the mutex, returning the underlying data