/// Connect to the server and start emitting periodic register messages.
/// Runs until the sender side of mpsc channel is closed.
Connect to the server and start emitting periodic register messages.
Runs until the sender side of mpsc channel is closed.
Connect to the server and start emitting periodic register messages . Runs until the sender side of mpsc channel is closed .
pub async fn run(
        &mut self,
        mut receiver: mpsc::Receiver<()>,
    ) -> Result<(), Error> {
        assert!(self.client.is_none());
        // We retry connect in loop until successful. Once connected the nats
        // library will handle reconnections for us.
        while self.client.is_none() {
            self.client = match self.connect().await {
                Ok(client) => Some(client),
                Err(err) => {
                    error!("{}", err);
                    delay_for(self.hb_interval).await;
                    continue;
                }
            };
        }
        info!("Connected to the NATS server {}", self.server);
        info!(
            "Registering '{}' and grpc server {} ...",
            self.node, self.grpc_endpoint
        );
        loop {
            if let Err(err) = self.register().await {
                error!("Registration failed: {:?}", err);
            };
            let _res = select! {
                () = delay_for(self.hb_interval).fuse() => (),
                msg = receiver.next() => {
                    match msg {
                        Some(_) => warn!("Messages have not been implemented yet"),
                        None => {
                            info!("Terminating the NATS client");
                            break;
                        }
                    }
                }
            };
        }
        if let Err(err) = self.deregister().await {
            error!("Deregistration failed: {:?}", err);
        };
        Ok(())
    }
pub async fn run ( & mut self , mut receiver : mpsc :: Receiver < ( ) > , ) -> Result < ( ) , Error > { assert ! ( self client is_none ( ) ) ; // We retry connect in loop until successful. Once connected the nats // library will handle reconnections for us. while self . client . is_none ( ) { self . client = match self . connect ( ) . await { Ok ( client ) => Some ( client ) , Err ( err ) => { error ! ( " " err ) ; delay_for ( self . hb_interval ) . await ; continue ; } } ; } info ! ( " " self server ) ; info ! ( " " self node self grpc_endpoint ) ; loop { if let Err ( err ) = self . register ( ) . await { error ! ( " " err ) ; } ; let _res = select ! { ( ) delay_for ( self hb_interval ) fuse ( ) ( ) msg receiver next ( ) { match msg { Some ( ) warn ( " " ) None { info ( " " ) break } } } } ; } if let Err ( err ) = self . deregister ( ) . await { error ! ( " " err ) ; } ; Ok ( ( ) ) }
Connect to the server and start emitting periodic register messages.
Connect to the server and start emitting periodic register messages .
&mut self
receiver
mpsc::Receiver<()>