TunnelsManager: fix use of arrayslice in addMultiple

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2018-11-03 04:37:56 +01:00
parent f57c40c38b
commit 5845db4568
+4 -5
View File
@@ -102,17 +102,16 @@ class TunnelsManager {
} }
func addMultiple(tunnelConfigurations: [TunnelConfiguration], completionHandler: @escaping (UInt) -> Void) { func addMultiple(tunnelConfigurations: [TunnelConfiguration], completionHandler: @escaping (UInt) -> Void) {
addMultiple(tunnelConfigurations: tunnelConfigurations[0...], numberSuccessful: 0, completionHandler: completionHandler) addMultiple(tunnelConfigurations: ArraySlice(tunnelConfigurations), numberSuccessful: 0, completionHandler: completionHandler)
} }
private func addMultiple(tunnelConfigurations: ArraySlice<TunnelConfiguration>, numberSuccessful: UInt, completionHandler: @escaping (UInt) -> Void) { private func addMultiple(tunnelConfigurations: ArraySlice<TunnelConfiguration>, numberSuccessful: UInt, completionHandler: @escaping (UInt) -> Void) {
if tunnelConfigurations.isEmpty { guard let head = tunnelConfigurations.first else {
completionHandler(numberSuccessful) completionHandler(numberSuccessful)
return return
} }
let head = tunnelConfigurations.first! let tail = tunnelConfigurations.dropFirst()
let tail = tunnelConfigurations[1...] self.add(tunnelConfiguration: head) { [weak self, tail] (tunnel, error) in
self.add(tunnelConfiguration: head) { [weak self] (tunnel, error) in
DispatchQueue.main.async { DispatchQueue.main.async {
self?.addMultiple(tunnelConfigurations: tail, numberSuccessful: numberSuccessful + (error == nil ? 1 : 0), completionHandler: completionHandler) self?.addMultiple(tunnelConfigurations: tail, numberSuccessful: numberSuccessful + (error == nil ? 1 : 0), completionHandler: completionHandler)
} }