fix: ouch mutexes are harddddd

This commit is contained in:
əlemi 2023-11-17 18:38:29 +01:00
parent 175b9c945a
commit 0ba2c5ccef

View file

@ -78,23 +78,20 @@ impl Controller<TextChange> for BufferController {
} }
fn try_recv(&self) -> crate::Result<Option<TextChange>> { fn try_recv(&self) -> crate::Result<Option<TextChange>> {
match self.seen.try_read() { let seen = match self.seen.try_read() {
Err(_) => Err(crate::Error::Deadlocked), Err(_) => return Err(crate::Error::Deadlocked),
Ok(x) => { Ok(x) => x.clone(),
if *self.content.borrow() != *x { };
match self.seen.try_write() { let actual = self.content.borrow().clone();
Err(_) => Err(crate::Error::Deadlocked), if seen == actual {
Ok(mut w) => { return Ok(None);
let change = TextChange::from_diff(&w, &self.content.borrow());
*w = self.content.borrow().clone();
Ok(Some(change))
}
}
} else {
Ok(None)
}
}
} }
let change = TextChange::from_diff(&seen, &actual);
match self.seen.try_write() {
Err(_) => return Err(crate::Error::Deadlocked),
Ok(mut w) => *w = actual,
};
Ok(Some(change))
} }
async fn recv(&self) -> crate::Result<TextChange> { async fn recv(&self) -> crate::Result<TextChange> {