OfflineRetrier
@available(macOS 10.14, iOS 12, tvOS 12, watchOS 5, visionOS 1, *)
public final class OfflineRetrier : RequestAdapter, RequestRetrier, RequestInterceptor, Sendable
RequestRetrier which uses NWPathMonitor to detect when connectivity is restored to retry failed requests.
-
Default amount of time to wait for connectivity to be restored before failure.
.seconds(5)by default.Declaration
Swift
public static let defaultWait: DispatchTimeInterval -
Default
Set<URLError.Code>used to check for offline errors.[.notConnectedToInternet]by default.Declaration
Swift
public static let defaultURLErrorOfflineCodes: Set<URLError.Code> -
Default method of detecting whether a particular
any Errormeans connectivity is offline.Declaration
Swift
public static let defaultIsOfflineError: @Sendable (_ error: any Error) -> Bool -
Creates an instance from the provided
NWPathMonitor, maximum wait for connectivity, and offline error predicate.Declaration
Swift
public init(monitor: @autoclosure @escaping () -> NWPathMonitor = NWPathMonitor(), maximumWait: DispatchTimeInterval = OfflineRetrier.defaultWait, isOfflineError: @escaping @Sendable (_ error: any Error) -> Bool = OfflineRetrier.defaultIsOfflineError)Parameters
monitorNWPathMonitor()to use to detect connectivity. A new instance is created each time a request fails and retry may be needed.maximumWaitDispatchTimeIntervalto wait for connectivity beforeisOfflineErrorPredicate closure used to determine whether a particular
any Errorindicates connectivity is offline. Returningfalsemoves to the next retrier, if any. -
Creates an instance using an
NWPathMonitorconfigured with the providedInterfaceType, maximum wait for connectivity, and offline error predicate.Declaration
Swift
public convenience init(requiredInterfaceType: NWInterface.InterfaceType, maximumWait: DispatchTimeInterval = OfflineRetrier.defaultWait, isOfflineError: @escaping @Sendable (_ error: any Error) -> Bool = OfflineRetrier.defaultIsOfflineError)Parameters
monitorNWInterface.InterfaceTypeused to configured theNWPathMonitoreach time one is needed.maximumWaitDispatchTimeIntervalto wait for connectivity beforeisOfflineErrorPredicate closure used to determine whether a particular
any Errorindicates connectivity is offline. Returningfalsemoves to the next retrier, if any. -
Creates an instance using an
NWPathMonitorconfigured with the providedInterfaceTypes, maximum wait for connectivity, and offline error predicate.Declaration
Swift
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, visionOS 1, *) public convenience init(prohibitedInterfaceTypes: [NWInterface.InterfaceType], maximumWait: DispatchTimeInterval = OfflineRetrier.defaultWait, isOfflineError: @escaping @Sendable (_ error: any Error) -> Bool = OfflineRetrier.defaultIsOfflineError)Parameters
monitor[NWInterface.InterfaceType]used to configured theNWPathMonitoreach time one is needed.maximumWaitDispatchTimeIntervalto wait for connectivity beforeisOfflineErrorPredicate closure used to determine whether a particular
any Errorindicates connectivity is offline. Returningfalsemoves to the next retrier, if any. -
Declaration
Swift
public func retry(_ request: Request, for session: Session, dueTo error: any Error, completion: @escaping @Sendable (RetryResult) -> Void)
View on GitHub
Install in Dash