diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-11-03 02:51:32 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-11-03 03:43:09 +0100 |
commit | 95101dce5cf230e398eb04b50d441723f6101869 (patch) | |
tree | 9689cb2d399c8ffb8c4ed48be335827dd322eabd /WireGuard/WireGuard/VPN/TunnelsManager.swift | |
parent | Tunnel detail: In the key-value cell, make the value label scrollable horizontally (diff) | |
download | wireguard-apple-95101dce5cf230e398eb04b50d441723f6101869.tar.xz wireguard-apple-95101dce5cf230e398eb04b50d441723f6101869.zip |
Import: rework addMultiple logic
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | WireGuard/WireGuard/VPN/TunnelsManager.swift | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index 7d5dd50..5015be0 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -119,23 +119,20 @@ class TunnelsManager { } } - func addMultiple(tunnelConfigurations: [TunnelConfiguration], completionHandler: @escaping (Int, TunnelManagementError?) -> Void) { - addMultiple(tunnelConfigurations: tunnelConfigurations[0...], completionHandler: completionHandler) + func addMultiple(tunnelConfigurations: [TunnelConfiguration], completionHandler: @escaping (UInt) -> Void) { + addMultiple(tunnelConfigurations: tunnelConfigurations[0...], numberSuccessful: 0, completionHandler: completionHandler) } - private func addMultiple(tunnelConfigurations: ArraySlice<TunnelConfiguration>, completionHandler: @escaping (Int, TunnelManagementError?) -> Void) { - assert(!tunnelConfigurations.isEmpty) + private func addMultiple(tunnelConfigurations: ArraySlice<TunnelConfiguration>, numberSuccessful: UInt, completionHandler: @escaping (UInt) -> Void) { + if tunnelConfigurations.isEmpty { + completionHandler(numberSuccessful) + return + } let head = tunnelConfigurations.first! - let tail = tunnelConfigurations[1 ..< tunnelConfigurations.count] + let tail = tunnelConfigurations[1...] self.add(tunnelConfiguration: head) { [weak self] (tunnel, error) in - if (error != nil) { - completionHandler(tail.count, error) - } else if (tail.isEmpty) { - completionHandler(0, nil) - } else { - DispatchQueue.main.async { - self?.addMultiple(tunnelConfigurations: tail, completionHandler: completionHandler) - } + DispatchQueue.main.async { + self?.addMultiple(tunnelConfigurations: tail, numberSuccessful: numberSuccessful + (error == nil ? 1 : 0), completionHandler: completionHandler) } } } |