Hold swaplock for less in change()

This commit is contained in:
Félix Saparelli 2022-01-16 14:48:29 +13:00
parent ed6df57aa0
commit 0618eb45fc
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
1 changed files with 2 additions and 1 deletions

View File

@ -34,7 +34,8 @@ where
/// This obtains a clone of the value, and then calls the closure with a mutable reference to
/// it. Once the closure returns, the value is swapped in.
pub async fn change(&self, f: impl FnOnce(&mut T)) -> Result<(), SendError<T>> {
let mut new = self.r.borrow().clone();
let mut new = { self.r.borrow().clone() };
f(&mut new);
self.s.send(new)
}