Swiftpack.co - bigearsenal/task-retrying-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by bigearsenal.
bigearsenal/task-retrying-swift 1.0.1
Extension for Task for retrying operations.
⭐️ 0
🕓 1 week ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/bigearsenal/task-retrying-swift.git", from: "1.0.1")


The extension that allows you to make a retriable Task using Swift concurrency.



pod install Task_retrying


.package(url: "https://github.com/bigearsenal/task-retrying-swift.git", from: "1.0.1"),


/// Create a retriable Task with deadline and max retry count
/// - Parameters:
///   - condition: Condition that indicates where to retry
///   - priority: (Optional) Priority of the task
///   - maxRetryCount: max number of retries, default is 3
///   - retryDelay: delay after each retries, default is 1 seconds
///   - timeoutInSeconds: timeout in seconds
///   - operation: operation that needs to do
/// - Returns: Retriable task
public static func retrying(
    where condition: @escaping (Error) -> Bool,
    priority: TaskPriority? = nil,
    maxRetryCount: Int = 3,
    retryDelay: TimeInterval = 1,
    timeoutInSeconds: Int? = nil,
    operation: @Sendable @escaping () async throws -> Success
) -> Task

How to use

try await Task.retrying(
    where: {error in error == .errorThatNeedToRetry},
    maxRetryCount: 3,
    retryDelay: 1,
    timeoutInSeconds: 30
) {
    try await doSomething()

Throwing errors

In case of exceeded max retry count or timed out, there would be errors:

public enum TaskRetryingError: Error {
    case timedOut
    case exceededMaxRetryCount


Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics