1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/// A module for utility functions, including retry logic.
///
/// This module provides functions to retry asynchronous operations with specified delays.
use Duration;
/// Retries a given asynchronous operation a specified number of times with a delay.
///
/// This function attempts to execute the provided operation up to `max_retries` times.
/// If the operation fails, it waits for the specified `delay` before retrying. If the
/// operation succeeds, the result is returned. If all attempts fail, an error is returned.
///
/// # Parameters
///
/// - `max_retries`: The maximum number of times to retry the operation.
/// - `delay`: The duration to wait between retry attempts.
/// - `operation`: A closure that returns a `Result<T, String>`. This closure is the
/// operation to be retried. It should return `Ok(T)` on success or `Err(String)`
/// on failure.
///
/// # Returns
///
/// This function returns a `Result<T, UtilError>`. On success, it returns `Ok(result)`
/// where `result` is the successful output of the operation. If all retry attempts fail,
/// it returns an `Err` containing a `UtilError` that describes the failure.
///
/// # Errors
///
/// The function can fail in several ways, including but not limited to:
/// - The operation returns an error after exhausting all retry attempts.
/// - The operation fails to execute due to other unforeseen issues.
pub async