persevero
persevero
executes a fallible operation multiple times.
Types
Represents errors that can occur during execution attempts.
pub type Error(a) {
RetriesExhausted(errors: List(a))
UnallowedError(error: a)
}
Constructors
-
RetriesExhausted(errors: List(a))
Indicates that all execution attempts have been exhausted. Contains an ordered list of all errors encountered during the execution attempts.
-
UnallowedError(error: a)
Indicates that an error that wasn’t allowed was encountered. Contains the specific error that caused execution to stop.
Functions
pub fn apply_constant(
yielder yielder: Yielder(Int),
adjustment adjustment: Int,
) -> Yielder(Int)
Adds a constant integer to each wait time.
pub fn apply_jitter(
yielder yielder: Yielder(Int),
upper_bound upper_bound: Int,
) -> Yielder(Int)
Adds a random integer between [1, upper_bound
] to each wait time.
pub fn execute(
yielder yielder: Yielder(Int),
allow allow: fn(a) -> Bool,
max_attempts max_attempts: Int,
operation operation: fn() -> Result(b, a),
) -> Result(b, Error(a))
Initiates the execution process with the specified operation.
allow
sets the logic for determining whether an error should trigger
another attempt. Expects a function that takes an error and returns a
boolean. Use this function to match on the encountered error and return
True
for errors that should trigger another attempt, and False
for
errors that should not. To allow all errors, use fn(_) { True }
.
pub fn max_wait_time(
yielder yielder: Yielder(Int),
max_wait_time max_wait_time: Int,
) -> Yielder(Int)
Sets a maximum time limit to wait between execution attempts.
pub fn new(
wait_time wait_time: Int,
backoff backoff: fn(Int) -> Int,
) -> Yielder(Int)
Creates a new configuration with the specified wait_time
and backoff
function.
The backoff
function determines how the wait time changes between
attempts. It takes the previous wait time as input and returns the next wait
time.