Browse Source

Moved sleep to the correct place

Cesar Rodas 1 year ago
parent
commit
bb0c86ebfd
4 changed files with 11 additions and 10 deletions
  1. 2 2
      crates/client/src/relayer.rs
  2. 3 2
      crates/relayer/src/connection.rs
  3. 5 0
      crates/relayer/src/error.rs
  4. 1 6
      src/bin/dump.rs

+ 2 - 2
crates/client/src/relayer.rs

@@ -150,9 +150,9 @@ impl Relayer {
                             break;
                         }
                     }
-                    // Throttle down to not spam the server with reconnections
-                    sleep(Duration::from_millis(500)).await;
                 }
+                // Throttle down to not spam the server with reconnections
+                sleep(Duration::from_millis(500)).await;
             }
 
             log::warn!("{}: Disconnected", url);

+ 3 - 2
crates/relayer/src/connection.rs

@@ -64,8 +64,9 @@ impl Connection {
         });
     }
 
-    pub async fn send(&self, _response: Response) -> Result<(), Error> {
-        Ok(())
+    #[inline]
+    pub fn send(&self, response: Response) -> Result<(), Error> {
+        Ok(self.sender.try_send(response)?)
     }
 
     pub fn create_connection(&self, id: String) -> Result<(u128, u128, Sender<Response>), Error> {

+ 5 - 0
crates/relayer/src/error.rs

@@ -1,3 +1,5 @@
+use nostr_rs_types::Response;
+
 #[derive(Debug, thiserror::Error)]
 pub enum Error {
     #[error("The identifier {0} is already in use")]
@@ -14,4 +16,7 @@ pub enum Error {
 
     #[error("Unknown connection: {0}")]
     UnknownConnection(u128),
+
+    #[error("TrySendError: {0}")]
+    TrySendError(#[from] tokio::sync::mpsc::error::TrySendError<Response>),
 }

+ 1 - 6
src/bin/dump.rs

@@ -41,17 +41,12 @@ async fn main() {
     let db = RocksDb::new("./db").expect("db");
 
     loop {
-        println!("going into loop");
         if let Some((msg, _relayed_by)) = clients.recv().await.expect("valid connection") {
             match msg {
                 Response::Event(x) => {
                     let event = x.event;
 
-                    if db.store(&event).expect("valid") {
-                        println!("\tStored");
-                    } else {
-                        println!("\tSkip");
-                    }
+                    let _ = db.store(&event).expect("valid");
                 }
                 _ => {}
             }