async fn wait_for_successful_rebuild(hdl: &mut RpcHandle, child: &str) -> bool {
    let mut last_progress = 0;
    let mut progress_start_time = std::time::Instant::now();
    let progress_window = std::time::Duration::from_secs(5);
    let time = std::time::Instant::now();
    const TIMEOUT: Duration = std::time::Duration::from_secs(30);

    // Keep looping while progress is being made and the rebuild has not timed
    // out.
    while std::time::Instant::now() - progress_start_time < progress_window
        || time.elapsed().as_millis() < TIMEOUT.as_millis()
    {
        match get_rebuild_progress(hdl, child).await {
            Some(progress) => {
                if progress - last_progress > 0 {
                    // Progress has been made, reset the progress window.
                    progress_start_time = std::time::Instant::now();
                    last_progress = progress;
                }
            }
            None => {
                // 'None' is returned when the rebuild job cannot be found -
                // which can indicate rebuild completion.
                // If the child is online, the rebuild completed successfully.
                return get_child_state(hdl, child).await
                    == ChildState::ChildOnline as i32;
            }
        }
        std::thread::sleep(Duration::from_millis(50));
    }
    return false;
}
/// Returns true if the rebuild has completed successfully i.e. the destination
/// child is 'online'.
/// Returns false if:
///     1. The rebuild does not make any progress within the progress window
///     2. The rebuild takes longer than the TIMEOUT time.
Returns true if the rebuild has completed successfully i.e. the destination
child is 'online'.
Returns false if:
1. The rebuild does not make any progress within the progress window
2. The rebuild takes longer than the TIMEOUT time.
Returns true if the rebuild has completed successfully i . e . the destination child is ' online ' . Returns false if : 1 . The rebuild does not make any progress within the progress window 2 . The rebuild takes longer than the TIMEOUT time .
async fn wait_for_successful_rebuild(hdl: &mut RpcHandle, child: &str) -> bool {
    let mut last_progress = 0;
    let mut progress_start_time = std::time::Instant::now();
    let progress_window = std::time::Duration::from_secs(5);
    let time = std::time::Instant::now();
    const TIMEOUT: Duration = std::time::Duration::from_secs(30);
    // Keep looping while progress is being made and the rebuild has not timed
    // out.
    while std::time::Instant::now() - progress_start_time < progress_window
        || time.elapsed().as_millis() < TIMEOUT.as_millis()
    {
        match get_rebuild_progress(hdl, child).await {
            Some(progress) => {
                if progress - last_progress > 0 {
                    // Progress has been made, reset the progress window.
                    progress_start_time = std::time::Instant::now();
                    last_progress = progress;
                }
            }
            None => {
                // 'None' is returned when the rebuild job cannot be found -
                // which can indicate rebuild completion.
                // If the child is online, the rebuild completed successfully.
                return get_child_state(hdl, child).await
                    == ChildState::ChildOnline as i32;
            }
        }
        std::thread::sleep(Duration::from_millis(50));
    }
    return false;
}
async fn wait_for_successful_rebuild ( hdl : & mut RpcHandle , child : & str ) -> bool { let mut last_progress = 0 ; let mut progress_start_time = std :: time :: Instant :: now ( ) ; let progress_window = std :: time :: Duration :: from_secs ( 5 ) ; let time = std :: time :: Instant :: now ( ) ; const TIMEOUT : Duration = std :: time :: Duration :: from_secs ( 30 ) ; // Keep looping while progress is being made and the rebuild has not timed // out. while std :: time :: Instant :: now ( ) - progress_start_time < progress_window || time . elapsed ( ) . as_millis ( ) < TIMEOUT . as_millis ( ) { match get_rebuild_progress ( hdl , child ) . await { Some ( progress ) => { if progress - last_progress > 0 { // Progress has been made, reset the progress window. progress_start_time = std :: time :: Instant :: now ( ) ; last_progress = progress ; } } None => { // 'None' is returned when the rebuild job cannot be found - // which can indicate rebuild completion. // If the child is online, the rebuild completed successfully. return get_child_state ( hdl , child ) . await == ChildState :: ChildOnline as i32 ; } } std :: thread :: sleep ( Duration :: from_millis ( 50 ) ) ; } return false ; }
Returns true if the rebuild has completed successfully i.e.
Returns true if the rebuild has completed successfully i . e .
hdl
&mut RpcHandle
child
&str