File tree Expand file tree Collapse file tree 1 file changed +20
-12
lines changed
WooCommerce/Classes/Tools/BackgroundTasks Expand file tree Collapse file tree 1 file changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -173,19 +173,27 @@ private struct BackgroundTaskSystemInfo {
173173 }
174174
175175 private static func getNetworkInfo( ) async -> NetworkInfo {
176- return await withCheckedContinuation { continuation in
177- let monitor = NWPathMonitor ( )
178- var hasResumed = false
179-
180- monitor. pathUpdateHandler = { path in
181- guard !hasResumed else { return }
182- hasResumed = true
183- monitor. cancel ( )
184- continuation. resume ( returning: NetworkInfo ( path: path) )
185- }
176+ let monitor = NWPathMonitor ( )
177+ let queue = DispatchQueue ( label: " network.monitor.queue " )
178+
179+ let ( stream, continuation) = AsyncStream . makeStream ( of: NWPath . self)
180+
181+ monitor. pathUpdateHandler = { path in
182+ continuation. yield ( path)
183+ }
186184
187- let queue = DispatchQueue ( label: " network.monitor.queue " )
188- monitor. start ( queue: queue)
185+ monitor. start ( queue: queue)
186+
187+ defer {
188+ continuation. finish ( )
189+ monitor. cancel ( )
190+ }
191+
192+ if let path = await stream. first ( where: { _ in true } ) {
193+ return NetworkInfo ( path: path)
194+ } else {
195+ // Fallback in case no path is received.
196+ return NetworkInfo ( type: " unknown " , isExpensive: false , isLowDataMode: false )
189197 }
190198 }
191199}
You can’t perform that action at this time.
0 commit comments