Просмотр исходного кода

Make network monitor and observer internal

Vladislav Komkov 4 месяцев назад
Родитель
Сommit
656b5bfc17
2 измененных файлов с 16 добавлено и 10 удалено
  1. 6 6
      Sources/Networking/NetworkMonitor.swift
  2. 10 4
      Sources/Networking/RetryStrategy.swift

+ 6 - 6
Sources/Networking/NetworkMonitor.swift

@@ -28,7 +28,7 @@ import Network
 import Foundation
 
 /// A protocol for network connectivity monitoring that allows for dependency injection and testing.
-public protocol NetworkMonitoring: Sendable {
+internal protocol NetworkMonitoring: Sendable {
     /// Whether the network is currently connected.
     var isConnected: Bool { get }
 
@@ -41,7 +41,7 @@ public protocol NetworkMonitoring: Sendable {
 }
 
 /// A protocol for network observers that can be cancelled.
-public protocol NetworkObserver: Sendable {
+internal protocol NetworkObserver: Sendable {
     /// Cancels the network observation.
     func cancel()
 }
@@ -49,11 +49,11 @@ public protocol NetworkObserver: Sendable {
 /// A shared singleton that manages network connectivity monitoring.
 /// This prevents creating multiple NWPathMonitor instances when many NetworkRetryStrategy instances are used.
 /// The monitor is created lazily only when first accessed.
-public final class NetworkMonitor: @unchecked Sendable, NetworkMonitoring {
-    public static let `default` = NetworkMonitor()
+internal final class NetworkMonitor: @unchecked Sendable, NetworkMonitoring {
+    static let `default` = NetworkMonitor()
 
     /// Whether the network is currently connected.
-    public var isConnected: Bool {
+    var isConnected: Bool {
         return monitor.currentPath.status == .satisfied
     }
 
@@ -173,7 +173,7 @@ internal final class NetworkObserverImpl: @unchecked Sendable, NetworkObserver {
         }
     }
 
-    public func cancel() {
+    func cancel() {
         queue.async { [weak self] in
             guard let self else { return }
 

+ 10 - 4
Sources/Networking/RetryStrategy.swift

@@ -204,10 +204,16 @@ public struct NetworkRetryStrategy: RetryStrategy {
     ///
     /// - Parameters:
     ///   - timeoutInterval: The timeout for waiting for network reconnection. If nil, no timeout is applied. Defaults to 30 seconds.
-    ///   - networkMonitor: The network monitoring service. Defaults to the shared NetworkMonitor instance.
-    public init(
-        timeoutInterval: TimeInterval? = 30,
-        networkMonitor: NetworkMonitoring = NetworkMonitor.default
+    public init(timeoutInterval: TimeInterval? = 30) {
+        self.init(
+            timeoutInterval: timeoutInterval,
+            networkMonitor: NetworkMonitor.default
+        )
+    }
+
+    internal init(
+        timeoutInterval: TimeInterval?,
+        networkMonitor: NetworkMonitoring
     ) {
         self.timeoutInterval = timeoutInterval
         self.networkMonitor = networkMonitor