summaryrefslogtreecommitdiff
path: root/src/client/connector.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/connector.rs')
-rw-r--r--src/client/connector.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/client/connector.rs b/src/client/connector.rs
index 6b59f60..3396349 100644
--- a/src/client/connector.rs
+++ b/src/client/connector.rs
@@ -5,6 +5,7 @@ use std::{thread::sleep, time::Duration};
use crate::executor::{Executor, tasks::IntoTask};
+#[derive(Debug)]
pub(crate) enum Result<T: std::fmt::Display + IntoTask, E: std::fmt::Debug> {
Ok(T),
Err(E),
@@ -17,16 +18,26 @@ pub(crate) trait Connection {
// should use channel to notify update
fn update(&self) -> Result<Self::Ok, Self::Err>; // None if no update(content is same)
+ // TODO: queue failed ntfy
fn ntfy(&self, data: String) -> Result<Self::Ok, Self::Err>;
fn is_prev(&mut self, str: &Self::Ok) -> bool;
+ fn force_network(&mut self);
+
+ fn reinit(&mut self) {
+ sleep(Duration::from_millis(500));
+ _ = Executor::new("network", ["on".to_string()]);
+ self.force_network();
+ }
+
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));
+ self.reinit();
+
match self.update() {
Result::Ok(s) => {
if self.is_prev(&s) {