diff options
Diffstat (limited to 'src/client/connector.rs')
| -rw-r--r-- | src/client/connector.rs | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/client/connector.rs b/src/client/connector.rs index 709b91d..cae944b 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -1,30 +1,49 @@ pub(crate) mod connectors; pub(crate) mod manager; -use std::{thread::sleep, time}; +use std::{thread::sleep, time::Duration}; + +use crate::executor::{Executor, tasks::IntoTask}; + +pub(crate) enum Result<T: std::fmt::Display + IntoTask, E: std::fmt::Display> { + Ok(T), + Err(E), +} pub(crate) trait Connection { + type Ok: std::fmt::Display + IntoTask + AsRef<str> = String; type Err: std::fmt::Display; - type Success: std::fmt::Display = String; // should use channel to notify update - fn update(&self) -> Option<Result<Self::Success, Self::Err>>; // None if no update(content is same) + fn update(&self) -> Option<Result<Self::Ok, Self::Err>>; // None if no update(content is same) + + fn ntfy(&self, data: String); fn r#loop(&self) -> ! { loop { - // if let Some(Err(e)) = self.update() { - // eprintln!("Error: {}", e) - // } match self.update() { - Some(Ok(s)) => { - // _ = self.channel.sender.send(res.clone()); // don't care if receiver is dropped - // _ = executor::new(res.as_str()); + Some(Result::Ok(s)) => { + let mut it = s.as_ref().split_whitespace(); + let task = match it.next() { + Some(t) => t, + None => continue, + }; + let args: String = it.collect(); + // FIXME: handle the errors... peak prod code + self.ntfy( + Executor::new(task, args) + .unwrap() + .run() + .unwrap() + .clone() + .unwrap(), + ); } - Some(Err(e)) => eprintln!("Error: {}", e), + Some(Result::Err(e)) => eprintln!("Error: {}", e), _ => {} } - sleep(time::Duration::from_secs(1)); + sleep(Duration::from_millis(500)); } } } |
