diff --git a/DuckDuckGo/NetworkProtectionStatusViewModel.swift b/DuckDuckGo/NetworkProtectionStatusViewModel.swift index ab3ca1f57b..eb603f6162 100644 --- a/DuckDuckGo/NetworkProtectionStatusViewModel.swift +++ b/DuckDuckGo/NetworkProtectionStatusViewModel.swift @@ -37,7 +37,6 @@ final class NetworkProtectionStatusViewModel: ObservableObject { private let serverInfoObserver: ConnectionServerInfoObserver private let errorObserver: ConnectionErrorObserver private var cancellables: Set = [] - private var delayedToggleReenableCancellable: Cancellable? // MARK: Error @@ -158,12 +157,11 @@ final class NetworkProtectionStatusViewModel: ObservableObject { // Each event cancels the previous delayed publisher $shouldDisableToggle .filter { $0 } - .map { - Just(!$0) - .delay(for: 2.0, scheduler: DispatchQueue.main) - .assign(to: \.shouldDisableToggle, onWeaklyHeld: self) + .map { _ -> AnyPublisher in + Just(false).delay(for: 2.0, scheduler: DispatchQueue.main).eraseToAnyPublisher() } - .assign(to: \.delayedToggleReenableCancellable, onWeaklyHeld: self) + .switchToLatest() + .assign(to: \.shouldDisableToggle, onWeaklyHeld: self) .store(in: &cancellables) }