diff options
Diffstat (limited to 'src/client/connector.rs')
| -rw-r--r-- | src/client/connector.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/client/connector.rs b/src/client/connector.rs index cae944b..88b1939 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -15,14 +15,24 @@ pub(crate) trait Connection { type Err: std::fmt::Display; // should use channel to notify update - fn update(&self) -> Option<Result<Self::Ok, Self::Err>>; // None if no update(content is same) + fn update(&self) -> Result<Self::Ok, Self::Err>; // None if no update(content is same) fn ntfy(&self, data: String); - fn r#loop(&self) -> ! { + fn is_prev(&mut self, str: &Self::Ok) -> bool; + + fn r#loop(&mut self) -> ! { loop { + // tradeoff: if I put this at the ened of the loop, then the continue would just skip it, and continue doing update() until with no waiting, this wastes lot of cpu/IO + // however, of course we can add a manual sleep before it continue and put this in the end, but that's code duplication + // the cons of the current approch is that the first time we've entered, it would start sleeping + sleep(Duration::from_millis(500)); match self.update() { - Some(Result::Ok(s)) => { + Result::Ok(s) => { + if self.is_prev(&s) { + continue; + } + let mut it = s.as_ref().split_whitespace(); let task = match it.next() { Some(t) => t, @@ -39,11 +49,8 @@ pub(crate) trait Connection { .unwrap(), ); } - Some(Result::Err(e)) => eprintln!("Error: {}", e), - _ => {} + Result::Err(e) => eprintln!("Error: {}", e), } - - sleep(Duration::from_millis(500)); } } } |
