TunnelsManager: fix use of arrayslice in addMultiple

This commit is contained in:
Jason A. Donenfeld 2018-11-03 04:37:56 +01:00
parent aa5634ee27
commit c025ff8024
1 changed files with 4 additions and 5 deletions

View File

@ -102,17 +102,16 @@ class TunnelsManager {
}
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) {
if tunnelConfigurations.isEmpty {
guard let head = tunnelConfigurations.first else {
completionHandler(numberSuccessful)
return
}
let head = tunnelConfigurations.first!
let tail = tunnelConfigurations[1...]
self.add(tunnelConfiguration: head) { [weak self] (tunnel, error) in
let tail = tunnelConfigurations.dropFirst()
self.add(tunnelConfiguration: head) { [weak self, tail] (tunnel, error) in
DispatchQueue.main.async {
self?.addMultiple(tunnelConfigurations: tail, numberSuccessful: numberSuccessful + (error == nil ? 1 : 0), completionHandler: completionHandler)
}