diff --git a/WooCommerce/Classes/Tools/BackgroundTasks/BackgroundTaskRefreshDispatcher.swift b/WooCommerce/Classes/Tools/BackgroundTasks/BackgroundTaskRefreshDispatcher.swift index e2921bf3eb1..59590882ebd 100644 --- a/WooCommerce/Classes/Tools/BackgroundTasks/BackgroundTaskRefreshDispatcher.swift +++ b/WooCommerce/Classes/Tools/BackgroundTasks/BackgroundTaskRefreshDispatcher.swift @@ -173,16 +173,33 @@ private struct BackgroundTaskSystemInfo { } private static func getNetworkInfo() async -> NetworkInfo { - return await withCheckedContinuation { continuation in - let monitor = NWPathMonitor() + let monitor = NWPathMonitor() + let queue = DispatchQueue(label: "network.monitor.queue") - monitor.pathUpdateHandler = { path in - monitor.cancel() - continuation.resume(returning: NetworkInfo(path: path)) - } + let (stream, continuation) = AsyncStream.makeStream(of: NWPath.self) + + monitor.pathUpdateHandler = { path in + continuation.yield(path) + } - let queue = DispatchQueue(label: "network.monitor.queue") - monitor.start(queue: queue) + monitor.start(queue: queue) + + defer { + continuation.finish() + monitor.cancel() + } + + let timeoutTask = Task { + try await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC) + continuation.finish() + } + + if let path = await stream.first(where: { _ in true }) { + timeoutTask.cancel() + return NetworkInfo(path: path) + } else { + // Fallback in case no path is received. + return NetworkInfo(type: "unknown", isExpensive: false, isLowDataMode: false) } } } diff --git a/config/Version.Public.xcconfig b/config/Version.Public.xcconfig index 1a6b51f39d1..9d855f941b1 100644 --- a/config/Version.Public.xcconfig +++ b/config/Version.Public.xcconfig @@ -1,4 +1,4 @@ CURRENT_PROJECT_VERSION = $VERSION_LONG MARKETING_VERSION = $VERSION_SHORT -VERSION_LONG = 23.3.0.1 +VERSION_LONG = 23.3.0.2 VERSION_SHORT = 23.3