Skip to content

2.1.0

Latest
Compare
Choose a tag to compare
@finestructure finestructure released this 19 Dec 12:55
1056b62
  • Adds an overload to attempt with a State parameter containing information about the current retry iteration: block: (State) throws → T or block: (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
    }
}