pub(super) fn monitor_server(
    mut conn: Connection,
    server: Weak<Server>,
    heartbeat_frequency: Option<Duration>,
) {
    std::thread::spawn(move || {
        let mut server_type = ServerType::Unknown;
        let heartbeat_frequency = heartbeat_frequency.unwrap_or(DEFAULT_HEARTBEAT_FREQUENCY);

        loop {
            server_type = match monitor_server_check(&mut conn, server_type, &server) {
                Some(server_type) => server_type,
                None => return,
            };

            let last_check = PreciseTime::now();

            let timed_out = match server.upgrade() {
                Some(server) => server.wait_timeout(heartbeat_frequency),
                None => return,
            };

            if !timed_out {
                let duration_since_last_check = last_check.to(PreciseTime::now());

                if duration_since_last_check < *MIN_HEARTBEAT_FREQUENCY {
                    let remaining_time = *MIN_HEARTBEAT_FREQUENCY - duration_since_last_check;

                    // Since MIN_HEARTBEAT_FREQUENCY is 500 and `duration_since_last_check` is less
                    // than it but still positive, we can be sure that the time::Duration can be
                    // successfully converted to a std::time::Duration. However, in the case of some
                    // bug causing this not to be true, rather than panicking the monitoring thread,
                    // we instead just don't sleep and proceed to checking the server a bit early.
                    if let Ok(remaining_time) = remaining_time.to_std() {
                        std::thread::sleep(remaining_time);
                    }
                }
            }
        }
    });
}
/// Starts a monitoring thread associated with a given Server. A weak reference is used to ensure
/// that the monitoring thread doesn't keep the server alive after it's been removed from the
/// topology or the client has been dropped.
Starts a monitoring thread associated with a given Server. A weak reference is used to ensure
that the monitoring thread doesn't keep the server alive after it's been removed from the
topology or the client has been dropped.
Starts a monitoring thread associated with a given Server . A weak reference is used to ensure that the monitoring thread doesn ' t keep the server alive after it ' s been removed from the topology or the client has been dropped .
pub(super) fn monitor_server(
    mut conn: Connection,
    server: Weak<Server>,
    heartbeat_frequency: Option<Duration>,
) {
    std::thread::spawn(move || {
        let mut server_type = ServerType::Unknown;
        let heartbeat_frequency = heartbeat_frequency.unwrap_or(DEFAULT_HEARTBEAT_FREQUENCY);
        loop {
            server_type = match monitor_server_check(&mut conn, server_type, &server) {
                Some(server_type) => server_type,
                None => return,
            };
            let last_check = PreciseTime::now();
            let timed_out = match server.upgrade() {
                Some(server) => server.wait_timeout(heartbeat_frequency),
                None => return,
            };
            if !timed_out {
                let duration_since_last_check = last_check.to(PreciseTime::now());
                if duration_since_last_check < *MIN_HEARTBEAT_FREQUENCY {
                    let remaining_time = *MIN_HEARTBEAT_FREQUENCY - duration_since_last_check;
                    // Since MIN_HEARTBEAT_FREQUENCY is 500 and `duration_since_last_check` is less
                    // than it but still positive, we can be sure that the time::Duration can be
                    // successfully converted to a std::time::Duration. However, in the case of some
                    // bug causing this not to be true, rather than panicking the monitoring thread,
                    // we instead just don't sleep and proceed to checking the server a bit early.
                    if let Ok(remaining_time) = remaining_time.to_std() {
                        std::thread::sleep(remaining_time);
                    }
                }
            }
        }
    });
}
pub ( super ) fn monitor_server ( mut conn : Connection , server : Weak < Server > , heartbeat_frequency : Option < Duration > , ) { std :: thread :: spawn ( move | | { let mut server_type = ServerType :: Unknown ; let heartbeat_frequency = heartbeat_frequency . unwrap_or ( DEFAULT_HEARTBEAT_FREQUENCY ) ; loop { server_type = match monitor_server_check ( & mut conn , server_type , & server ) { Some ( server_type ) => server_type , None => return , } ; let last_check = PreciseTime :: now ( ) ; let timed_out = match server . upgrade ( ) { Some ( server ) => server . wait_timeout ( heartbeat_frequency ) , None => return , } ; if ! timed_out { let duration_since_last_check = last_check . to ( PreciseTime :: now ( ) ) ; if duration_since_last_check < * MIN_HEARTBEAT_FREQUENCY { let remaining_time = * MIN_HEARTBEAT_FREQUENCY - duration_since_last_check ; // Since MIN_HEARTBEAT_FREQUENCY is 500 and `duration_since_last_check` is less // than it but still positive, we can be sure that the time::Duration can be // successfully converted to a std::time::Duration. However, in the case of some // bug causing this not to be true, rather than panicking the monitoring thread, // we instead just don't sleep and proceed to checking the server a bit early. if let Ok ( remaining_time ) = remaining_time . to_std ( ) { std :: thread :: sleep ( remaining_time ) ; } } } } } ) ; }
Starts a monitoring thread associated with a given Server.
Starts a monitoring thread associated with a given Server .
conn
Connection
server
Weak<Server>
heartbeat_frequency
Option<Duration>
conn
Connection
server
Weak<Server>
heartbeat_frequency
Option<Duration>