pub async fn collect_and_retry<T, C, D, S>(
        &self,
        task: T,
        success_condition: C,
        error_condition: D,
        start_value: S,
    ) -> Result<Vec<T::Item>, T::Error>
    where
        T: TaskWithParameter<S>,
        C: SuccessCondition<T::Item, S>,
        D: Condition<T::Error>,
        S: Clone,
    {
        let mut success_backoffs = self.backoffs();
        let mut error_backoffs = self.backoffs();
        let mut success_condition = success_condition;
        let mut error_condition = error_condition;
        let mut task = task;
        let mut results = vec![];
        let mut input = start_value.clone();
        let mut last_result = start_value;

        loop {
            match task.call(input).await {
                Ok(result) => {
                    let maybe_new_input = success_condition.retry_with(&result);
                    results.push(result);

                    if let Some(new_input) = maybe_new_input {
                        if let Some(delay) = success_backoffs.next() {
                            #[cfg(feature = "log")]
                            {
                                log::trace!(
                                    "task succeeded and condition is met. will run again in {:?}",
                                    delay
                                );
                            }
                            let _ = Delay::new(delay).await;
                            input = new_input.clone();
                            last_result = new_input;
                            continue;
                        }
                    }

                    return Ok(results);
                }
                Err(err) => {
                    if error_condition.is_retryable(&err) {
                        if let Some(delay) = error_backoffs.next() {
                            #[cfg(feature = "log")]
                            {
                                log::trace!(
                                    "task failed with error {:?}. will try again in {:?}",
                                    err,
                                    delay
                                );
                            }
                            let _ = Delay::new(delay).await;
                            input = last_result.clone();
                            continue;
                        }
                    }
                    return Err(err);
                }
            }
        }
    }
/// Reruns and collects the results of a `Future`, if successful, with this policy's
/// configuration under a certain provided success condition. Also retries the `Future`, if
/// not successful under the same policy configuration and the provided error condition.
Reruns and collects the results of a `Future`, if successful, with this policy's
configuration under a certain provided success condition. Also retries the `Future`, if
not successful under the same policy configuration and the provided error condition.
Reruns and collects the results of a ` Future ` if successful with this policy ' s configuration under a certain provided success condition . Also retries the ` Future ` if not successful under the same policy configuration and the provided error condition .
pub async fn collect_and_retry<T, C, D, S>(
        &self,
        task: T,
        success_condition: C,
        error_condition: D,
        start_value: S,
    ) -> Result<Vec<T::Item>, T::Error>
    where
        T: TaskWithParameter<S>,
        C: SuccessCondition<T::Item, S>,
        D: Condition<T::Error>,
        S: Clone,
    {
        let mut success_backoffs = self.backoffs();
        let mut error_backoffs = self.backoffs();
        let mut success_condition = success_condition;
        let mut error_condition = error_condition;
        let mut task = task;
        let mut results = vec![];
        let mut input = start_value.clone();
        let mut last_result = start_value;
        loop {
            match task.call(input).await {
                Ok(result) => {
                    let maybe_new_input = success_condition.retry_with(&result);
                    results.push(result);
                    if let Some(new_input) = maybe_new_input {
                        if let Some(delay) = success_backoffs.next() {
                            #[cfg(feature = "log")]
                            {
                                log::trace!(
                                    "task succeeded and condition is met. will run again in {:?}",
                                    delay
                                );
                            }
                            let _ = Delay::new(delay).await;
                            input = new_input.clone();
                            last_result = new_input;
                            continue;
                        }
                    }
                    return Ok(results);
                }
                Err(err) => {
                    if error_condition.is_retryable(&err) {
                        if let Some(delay) = error_backoffs.next() {
                            #[cfg(feature = "log")]
                            {
                                log::trace!(
                                    "task failed with error {:?}. will try again in {:?}",
                                    err,
                                    delay
                                );
                            }
                            let _ = Delay::new(delay).await;
                            input = last_result.clone();
                            continue;
                        }
                    }
                    return Err(err);
                }
            }
        }
    }
pub async fn collect_and_retry < T , C , D , S > ( & self , task : T , success_condition : C , error_condition : D , start_value : S , ) -> Result < Vec < T :: Item > , T :: Error > where T : TaskWithParameter < S > , C : SuccessCondition < T :: Item , S > , D : Condition < T :: Error > , S : Clone , { let mut success_backoffs = self . backoffs ( ) ; let mut error_backoffs = self . backoffs ( ) ; let mut success_condition = success_condition ; let mut error_condition = error_condition ; let mut task = task ; let mut results = vec ! [ ] ; let mut input = start_value . clone ( ) ; let mut last_result = start_value ; loop { match task . call ( input ) . await { Ok ( result ) => { let maybe_new_input = success_condition . retry_with ( & result ) ; results . push ( result ) ; if let Some ( new_input ) = maybe_new_input { if let Some ( delay ) = success_backoffs . next ( ) { # [ cfg ( feature " " ) ] { log :: trace ! ( " " delay ) ; } let _ = Delay :: new ( delay ) . await ; input = new_input . clone ( ) ; last_result = new_input ; continue ; } } return Ok ( results ) ; } Err ( err ) => { if error_condition . is_retryable ( & err ) { if let Some ( delay ) = error_backoffs . next ( ) { # [ cfg ( feature " " ) ] { log :: trace ! ( " " err delay ) ; } let _ = Delay :: new ( delay ) . await ; input = last_result . clone ( ) ; continue ; } } return Err ( err ) ; } } } }
Reruns and collects the results of a `Future`, if successful, with this policy's
configuration under a certain provided success condition.
Reruns and collects the results of a ` Future ` if successful with this policy ' s configuration under a certain provided success condition .
&self
task
T
success_condition
C
error_condition
D
start_value
S
&self
task
T
success_condition
C
error_condition
D
start_value
S