mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 23:44:55 +01:00
chore: aligned match case, renamed to unwrap_or_warn
This commit is contained in:
parent
2c695a41f6
commit
b9ab3403dd
3 changed files with 17 additions and 16 deletions
|
@ -78,17 +78,18 @@ impl CodempClient {
|
||||||
|
|
||||||
let _factory = factory.clone();
|
let _factory = factory.clone();
|
||||||
let _path = path.clone();
|
let _path = path.clone();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
if !_factory.run() { break debug!("downstream worker clean exit") }
|
if !_factory.run() { break debug!("downstream worker clean exit") }
|
||||||
match stream.message().await {
|
match stream.message().await {
|
||||||
Err(e) => break error!("error receiving update: {}", e),
|
Err(e) => break error!("error receiving update: {}", e),
|
||||||
Ok(None) => break warn!("stream closed for buffer {}", _path),
|
Ok(None) => break warn!("stream closed for buffer {}", _path),
|
||||||
Ok(Some(x)) => match serde_json::from_str::<OperationSeq>(&x.opseq) {
|
Ok(Some(x)) => match serde_json::from_str::<OperationSeq>(&x.opseq) {
|
||||||
Err(e) => error!("error deserializing opseq: {}", e),
|
Err(e) => error!("error deserializing opseq: {}", e),
|
||||||
Ok(v) => match _factory.process(v).await {
|
Ok(v) => match _factory.process(v).await {
|
||||||
Err(e) => break error!("could not apply operation from server: {}", e),
|
Err(e) => break error!("could not apply operation from server: {}", e),
|
||||||
Ok(_range) => { } // user gets this range by awaiting wait() so we can drop it here
|
Ok(_range) => { } // range is obtained awaiting wait(), need to pass the OpSeq itself
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
pub trait IgnorableError {
|
pub trait IgnorableError {
|
||||||
fn unwrap_or_log(self, msg: &str);
|
fn unwrap_or_warn(self, msg: &str);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> IgnorableError for Result<T, E>
|
impl<T, E> IgnorableError for Result<T, E>
|
||||||
where E : std::fmt::Display {
|
where E : std::fmt::Display {
|
||||||
fn unwrap_or_log(self, msg: &str) {
|
fn unwrap_or_warn(self, msg: &str) {
|
||||||
match self {
|
match self {
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => warn!("{}: {}", msg, e),
|
Err(e) => warn!("{}: {}", msg, e),
|
||||||
|
|
|
@ -38,8 +38,8 @@ impl OperationController {
|
||||||
pub async fn wait(&self) -> Range<u64> {
|
pub async fn wait(&self) -> Range<u64> {
|
||||||
let mut blocker = self.changed.lock().unwrap().clone();
|
let mut blocker = self.changed.lock().unwrap().clone();
|
||||||
// TODO less jank way
|
// TODO less jank way
|
||||||
blocker.changed().await.unwrap_or_log("waiting for changed content #1");
|
blocker.changed().await.unwrap_or_warn("waiting for changed content #1");
|
||||||
blocker.changed().await.unwrap_or_log("waiting for changed content #2");
|
blocker.changed().await.unwrap_or_warn("waiting for changed content #2");
|
||||||
let span = blocker.borrow().clone();
|
let span = blocker.borrow().clone();
|
||||||
span
|
span
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ impl OperationController {
|
||||||
if len <= 0 {
|
if len <= 0 {
|
||||||
let mut recv = self.last.lock().unwrap().clone();
|
let mut recv = self.last.lock().unwrap().clone();
|
||||||
// TODO less jank way
|
// TODO less jank way
|
||||||
recv.changed().await.unwrap_or_log("wairing for op changes #1"); // acknowledge current state
|
recv.changed().await.unwrap_or_warn("wairing for op changes #1"); // acknowledge current state
|
||||||
recv.changed().await.unwrap_or_log("wairing for op changes #2"); // wait for a change in state
|
recv.changed().await.unwrap_or_warn("wairing for op changes #2"); // wait for a change in state
|
||||||
}
|
}
|
||||||
Some(self.queue.lock().unwrap().get(0)?.clone())
|
Some(self.queue.lock().unwrap().get(0)?.clone())
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,8 @@ impl OperationController {
|
||||||
pub fn stop(&self) -> bool {
|
pub fn stop(&self) -> bool {
|
||||||
match self.stop.send(false) {
|
match self.stop.send(false) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
self.changed_notifier.send(0..0).unwrap_or_log("unlocking downstream for stop");
|
self.changed_notifier.send(0..0).unwrap_or_warn("unlocking downstream for stop");
|
||||||
self.notifier.send(OperationSeq::default()).unwrap_or_log("unlocking upstream for stop");
|
self.notifier.send(OperationSeq::default()).unwrap_or_warn("unlocking upstream for stop");
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -96,7 +96,7 @@ impl OperationProcessor for OperationController {
|
||||||
async fn apply(&self, op: OperationSeq) -> Result<Range<u64>, OTError> {
|
async fn apply(&self, op: OperationSeq) -> Result<Range<u64>, OTError> {
|
||||||
let span = self.operation(&op).await?;
|
let span = self.operation(&op).await?;
|
||||||
self.queue.lock().unwrap().push_back(op.clone());
|
self.queue.lock().unwrap().push_back(op.clone());
|
||||||
self.notifier.send(op.clone()).unwrap_or_log("notifying of applied change");
|
self.notifier.send(op.clone()).unwrap_or_warn("notifying of applied change");
|
||||||
Ok(span)
|
Ok(span)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ impl OperationProcessor for OperationController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let span = self.operation(&op).await?;
|
let span = self.operation(&op).await?;
|
||||||
self.changed_notifier.send(span.clone()).unwrap_or_log("notifying of changed content");
|
self.changed_notifier.send(span.clone()).unwrap_or_warn("notifying of changed content");
|
||||||
Ok(span)
|
Ok(span)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue