mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
fix: ouch mutexes are harddddd
This commit is contained in:
parent
175b9c945a
commit
0ba2c5ccef
1 changed files with 13 additions and 16 deletions
|
@ -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> {
|
||||||
|
|
Loading…
Reference in a new issue