mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
fix: better try_recv mutex logic for cursor ctrl
This commit is contained in:
parent
2a016a6619
commit
ab9c6530cd
1 changed files with 10 additions and 8 deletions
|
@ -67,14 +67,16 @@ impl Controller<Cursor> for CursorController {
|
||||||
|
|
||||||
/// try to receive without blocking, but will still block on stream mutex
|
/// try to receive without blocking, but will still block on stream mutex
|
||||||
fn try_recv(&self) -> crate::Result<Option<Cursor>> {
|
fn try_recv(&self) -> crate::Result<Option<Cursor>> {
|
||||||
let mut stream = self.0.stream.blocking_lock();
|
match self.0.stream.try_lock() {
|
||||||
match stream.try_recv() {
|
Err(_) => Ok(None),
|
||||||
Ok(x) => Ok(Some(x.into())),
|
Ok(mut stream) => match stream.try_recv() {
|
||||||
Err(TryRecvError::Empty) => Ok(None),
|
Ok(x) => Ok(Some(x.into())),
|
||||||
Err(TryRecvError::Closed) => Err(crate::Error::Channel { send: false }),
|
Err(TryRecvError::Empty) => Ok(None),
|
||||||
Err(TryRecvError::Lagged(n)) => {
|
Err(TryRecvError::Closed) => Err(crate::Error::Channel { send: false }),
|
||||||
tracing::warn!("cursor channel lagged, skipping {} events", n);
|
Err(TryRecvError::Lagged(n)) => {
|
||||||
Ok(stream.try_recv().map(|x| x.into()).ok())
|
tracing::warn!("cursor channel lagged, skipping {} events", n);
|
||||||
|
Ok(stream.try_recv().map(|x| x.into()).ok())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue