fix: Out of bounds panic when not retrying push
This commit is contained in:
parent
82606cc144
commit
464fdf94a9
4 changed files with 13 additions and 18 deletions
|
|
@ -70,18 +70,17 @@ pub fn serde_yaml_err(contents: &str) -> impl Fn(serde_yaml::Error) -> SerdeErro
|
|||
///
|
||||
/// # Errors
|
||||
/// Will error when retries have been expended.
|
||||
pub fn retry<V, F>(attempts: u8, delay: u64, f: F) -> miette::Result<V>
|
||||
pub fn retry<V, F>(mut retries: u8, delay_secs: u64, f: F) -> miette::Result<V>
|
||||
where
|
||||
F: Fn() -> miette::Result<V>,
|
||||
{
|
||||
let mut attempts = attempts;
|
||||
loop {
|
||||
match f() {
|
||||
Ok(v) => return Ok(v),
|
||||
Err(e) if attempts == 1 => return Err(e),
|
||||
Err(e) if retries == 0 => return Err(e),
|
||||
_ => {
|
||||
attempts -= 1;
|
||||
thread::sleep(Duration::from_secs(delay));
|
||||
retries -= 1;
|
||||
thread::sleep(Duration::from_secs(delay_secs));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue