- Adds an overload to
attempt
with aState
parameter containing information about the current retry iteration:block: (State) throws → T
orblock: (State) async throws → T
. This allows you to act on that state in your retry block, for instance
try Retry.attempt("", delay: 0, retries: 3) { retry in
print(retry.isFirstIteration)
}
with State
:
public struct State {
public var retriesLeft: Int
public var currentTry = 0
public var lastError: Swift.Error?
public var isFirstIteration: Bool { currentTry == 0 }
public var hasRetriesLeft: Bool { retriesLeft > 0 }
mutating func advance() {
currentTry += 1
retriesLeft -= 1
}
}