mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-26 06:05:20 +00:00
Harden panic recovery and service shutdown
This commit is contained in:
@@ -27,6 +27,8 @@ protocol NetworkReachabilityMonitoring: AnyObject {
|
||||
var reachabilityPublisher: AnyPublisher<Bool, Never> { get }
|
||||
/// Begin monitoring. Idempotent.
|
||||
func start()
|
||||
/// Stop monitoring and discard pending debounce work. Idempotent.
|
||||
func stop()
|
||||
}
|
||||
|
||||
/// Pure debounce/decision logic for reachability, split out so it can be
|
||||
@@ -98,6 +100,7 @@ final class AlwaysReachableMonitor: NetworkReachabilityMonitoring {
|
||||
Empty(completeImmediately: false).eraseToAnyPublisher()
|
||||
}
|
||||
func start() {}
|
||||
func stop() {}
|
||||
}
|
||||
|
||||
/// `NWPathMonitor`-backed reachability. All state lives on the main actor; the
|
||||
@@ -146,6 +149,18 @@ final class NWPathReachabilityMonitor: NetworkReachabilityMonitoring {
|
||||
#endif
|
||||
}
|
||||
|
||||
func stop() {
|
||||
guard started else { return }
|
||||
started = false
|
||||
flushWorkItem?.cancel()
|
||||
flushWorkItem = nil
|
||||
#if canImport(Network)
|
||||
monitor?.pathUpdateHandler = nil
|
||||
monitor?.cancel()
|
||||
monitor = nil
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Feed an observation into the debounce and publish committed changes.
|
||||
/// Exposed internally so higher layers/tests could drive it if needed.
|
||||
func ingest(reachable: Bool) {
|
||||
|
||||
Reference in New Issue
Block a user