/// connect to leader, if can't connect try until we succeed
/// or if we received termination message
connect to leader, if can't connect try until we succeed
or if we received termination message
connect to leader if can ' t connect try until we succeed or if we received termination message
async fn create_socket_to_leader(&mut self) -> Option<KfSocket> {
        let leader_spu = self.get_spu().await;
        let leader_endpoint = leader_spu.private_endpoint.to_string();
        loop {
            trace!("trying to create socket to leader: {} at: {}", self.leader_id,leader_endpoint);
            let connect_future = KfSocket::connect(&leader_endpoint);
            select! {
                msg = self.receiver.next() => {
                    if let Some(cmd) = msg {
                        match cmd {
                            FollowerReplicaControllerCommand::AddReplica(replica) => self.update_replica(replica).await,
                            FollowerReplicaControllerCommand::UpdateReplica(replica) => self.update_replica(replica).await
                        }
                    } else {
                        error!("mailbox seems terminated, we should termina also");
                        return None
                    }
                },
                socket_res = connect_future.fuse() => {
                    match socket_res {
                        Ok(socket) => {
                            trace!("connected to leader: {}",self.leader_id);
                            return Some(socket)
                        }
                        Err(err) => error!("error connecting to leader: {}",err)
                    }
                    trace!("sleeping 5 seconds to connect to leader: {}",self.leader_id);
                    sleep(Duration::from_secs(5)).await;
                }
            }
        }
    }
async fn create_socket_to_leader ( & mut self ) -> Option < KfSocket > { let leader_spu = self . get_spu ( ) . await ; let leader_endpoint = leader_spu . private_endpoint . to_string ( ) ; loop { trace ! ( " " self leader_id leader_endpoint ) ; let connect_future = KfSocket :: connect ( & leader_endpoint ) ; select ! { msg self receiver next ( ) { if let Some ( cmd ) msg { match cmd { FollowerReplicaControllerCommand AddReplica ( replica ) self update_replica ( replica ) await FollowerReplicaControllerCommand UpdateReplica ( replica ) self update_replica ( replica ) await } } else { error ( " " ) return None } } socket_res connect_future fuse ( ) { match socket_res { Ok ( socket ) { trace ( " " self leader_id ) return Some ( socket ) } Err ( err ) error ( " " err ) } trace ( " " self leader_id ) sleep ( Duration from_secs ( 5 ) ) await } } } }
connect to leader, if can't connect try until we succeed
or if we received termination message
connect to leader if can ' t connect try until we succeed or if we received termination message
&mut self