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 2.0.0
Extension for Task for retrying operations.
⭐️ 8
🕓 1 year ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/bigearsenal/task-retrying-swift.git", from: "2.0.0")

Task_retrying

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

Installation

Cocoapods

pod install Task_retrying

SPM

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

Interface

/// 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()
}
    .value

Throwing errors

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

public enum TaskRetryingError: Error {
    case timedOut
    case exceededMaxRetryCount
}

GitHub

link
Stars: 8
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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