aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift24
1 files changed, 22 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index a94d63d7..3f7d9f5f 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -240,8 +240,7 @@ class TunnelsManager {
completionHandler(TunnelsManagerError.systemErrorOnRemoveTunnel(systemError: error!))
return
}
- if let self = self {
- let index = self.tunnels.firstIndex(of: tunnel)!
+ if let self = self, let index = self.tunnels.firstIndex(of: tunnel) {
self.tunnels.remove(at: index)
self.tunnelsListDelegate?.tunnelRemoved(at: index, tunnel: tunnel)
}
@@ -249,6 +248,27 @@ class TunnelsManager {
}
}
+ func removeMultiple(tunnels: [TunnelContainer], completionHandler: @escaping (TunnelsManagerError?) -> Void) {
+ removeMultiple(tunnels: ArraySlice(tunnels), completionHandler: completionHandler)
+ }
+
+ private func removeMultiple(tunnels: ArraySlice<TunnelContainer>, completionHandler: @escaping (TunnelsManagerError?) -> Void) {
+ guard let head = tunnels.first else {
+ completionHandler(nil)
+ return
+ }
+ let tail = tunnels.dropFirst()
+ remove(tunnel: head) { [weak self, tail] error in
+ DispatchQueue.main.async {
+ if let error = error {
+ completionHandler(error)
+ } else {
+ self?.removeMultiple(tunnels: tail, completionHandler: completionHandler)
+ }
+ }
+ }
+ }
+
func numberOfTunnels() -> Int {
return tunnels.count
}