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
Auto Trait Implementations§
impl<T> !Freeze for Mutex<T>
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> Send for Mutex<T>where
T: Send,
impl<T> !Sync for Mutex<T>
impl<T> Unpin for Mutex<T>where
T: Unpin,
impl<T> UnwindSafe for Mutex<T>where
T: UnwindSafe,
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