summaryrefslogtreecommitdiff
path: root/src/client/connector.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-09-01 18:06:03 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-09-01 18:06:03 +0800
commite4a1fbbd596b5466b266a077cddd104933b4fbcf (patch)
treef5baa9e21d9b08c2d401428858505e09c3d1c396 /src/client/connector.rs
init
Diffstat (limited to 'src/client/connector.rs')
-rw-r--r--src/client/connector.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/client/connector.rs b/src/client/connector.rs
new file mode 100644
index 0000000..a846939
--- /dev/null
+++ b/src/client/connector.rs
@@ -0,0 +1,41 @@
+mod connectors;
+pub(crate) mod manager;
+
+use std::{
+ sync::mpsc::{channel, Receiver, Sender},
+ thread::sleep,
+ time,
+};
+
+struct Channel<C: Connection> {
+ sender: Sender<C::Success>,
+ receiver: Receiver<()>,
+}
+
+impl<C: Connection> Channel<C> {
+ fn new() -> Self {
+ let (sender, _): (Sender<C::Success>, Receiver<C::Success>) = channel();
+ let (_, receiver): (Sender<()>, Receiver<()>) = channel();
+ Self { sender, receiver }
+ }
+}
+
+trait Connection {
+ type Err: std::fmt::Display;
+ type Success: std::fmt::Display = String;
+
+ fn test_connection(&self) -> Result<bool, Self::Err>;
+
+ // should use channel to notify update
+ async fn update(&self) -> Option<Result<Self::Success, Self::Err>>; // None if no update(content is same)
+
+ async fn r#loop(&self) -> ! {
+ loop {
+ if let Some(Err(e)) = self.update().await {
+ eprintln!("Error: {}", e)
+ }
+
+ sleep(time::Duration::from_secs(1));
+ }
+ }
+}