retry.bend source
retry.bend on the hub · documented module
import Basetype RetryPolicy is Data: Policy{initial_ms: U32, multiplier: U32, max_ms: U32, max_attempts: Nat}def Retry.default() -> RetryPolicy: Policy{500, 10, 10000, 3n}def Retry.permanent_code() -> U32: 499def Retry.permanent(msg: String) -> Result<&1, &1, U32 & String, Unit>: Fail{(Retry.permanent_code(), msg)}def Retry.when_not_permanent(policy: RetryPolicy, attempt: Nat) -> Bool: match policy: case Policy{initial, mult, max, max_attempts}: Nat.is_lt(attempt, max_attempts)def Retry.when_permanent(flag: Bool, policy: RetryPolicy, attempt: Nat) -> Bool: match flag: case True{}: False{} case False{}: Retry.when_not_permanent(policy, attempt)def Retry.is_permanent(r: Result<&1, &1, U32 & String, Unit>) -> Bool: match r: case Fail{(code, _)}: U32.is_eq(code, Retry.permanent_code()) case Done{_}: False{}def Retry.should_retry(policy: RetryPolicy, attempt: Nat, r: Result<&1, &1, U32 & String, Unit>) -> Bool: match r: case Done{_}: False{} case Fail{(code, _)}: Retry.when_permanent(U32.is_eq(code, Retry.permanent_code()), policy, attempt)def Retry.sleep(policy: RetryPolicy, attempt: Nat) -> IO(Unit): match policy: case Policy{initial, mult, max, _}: IO.sleep(initial)