// Attempt to get matching components `NUM_ATTEMPTS` times. If all attempts fail, return the
// last error encountered.
//
// This fixes an issue (fxbug.dev/84805) where the component topology may be mutating while the
// hub is being traversed, resulting in failures.
Attempt to get matching components `NUM_ATTEMPTS` times. If all attempts fail, return the
last error encountered.

This fixes an issue (fxbug.dev/84805) where the component topology may be mutating while the
hub is being traversed, resulting in failures.
Attempt to get matching components ` NUM_ATTEMPTS ` times . If all attempts fail return the last error encountered . This fixes an issue ( fxbug . dev / 84805 ) where the component topology may be mutating while the hub is being traversed resulting in failures .
pub async fn try_get_components(
    query: String,
    hub_dir: Directory,
    writer: &Writer,
) -> Result<Vec<Component>> {
    let mut attempt_number = 1;
    loop {
        match find_components(query.clone(), hub_dir.clone()?).await {
            Ok(components) => return Ok(components),
            Err(e) => {
                if attempt_number > NUM_ATTEMPTS {
                    return Err(e);
                } else {
                    writer.error(format!("Retrying. Attempt #{} failed: {}", attempt_number, e))?;
                }
            }
        }
        attempt_number += 1;
    }
}
pub async fn try_get_components ( query : String , hub_dir : Directory , writer : & Writer , ) -> Result < Vec < Component > > { let mut attempt_number = 1 ; loop { match find_components ( query . clone ( ) , hub_dir . clone ( ) ? ) . await { Ok ( components ) => return Ok ( components ) , Err ( e ) => { if attempt_number > NUM_ATTEMPTS { return Err ( e ) ; } else { writer . error ( format ! ( " " attempt_number e ) ) ? ; } } } attempt_number += 1 ; } }
Attempt to get matching components `NUM_ATTEMPTS` times.
Attempt to get matching components ` NUM_ATTEMPTS ` times .
query
String
hub_dir
Directory
writer
&Writer