burrow/Apple/UI/NetworkExtension+Async.swift
Conrad Kramer 85640ffce1
Some checks are pending
Build AppImage / Build AppImage (push) Waiting to run
Build Apple Apps / Build App (iOS) (push) Waiting to run
Build Apple Apps / Build App (iOS Simulator) (push) Waiting to run
Build Apple Apps / Build App (macOS) (push) Waiting to run
Build Docker / Build Docker Image (push) Waiting to run
Build Rust Crate / Build Crate (macOS (Intel)) (push) Waiting to run
Build Rust Crate / Build Crate (macOS) (push) Waiting to run
Build Rust Crate / Build Crate (Linux) (push) Waiting to run
Build Rust Crate / Build Crate (Windows) (push) Waiting to run
Switch to gRPC client in Swift app
2024-09-09 10:38:13 -07:00

45 lines
1.4 KiB
Swift

import NetworkExtension
extension NEVPNManager: @unchecked @retroactive Sendable {
func remove() async throws {
_ = try await withUnsafeThrowingContinuation { continuation in
removeFromPreferences(completionHandler: completion(continuation))
}
}
func save() async throws {
_ = try await withUnsafeThrowingContinuation { continuation in
saveToPreferences(completionHandler: completion(continuation))
}
}
}
extension NETunnelProviderManager: @unchecked @retroactive Sendable {
class var managers: [NETunnelProviderManager] {
get async throws {
try await withUnsafeThrowingContinuation { continuation in
loadAllFromPreferences(completionHandler: completion(continuation))
}
}
}
}
private func completion(_ continuation: UnsafeContinuation<Void, Error>) -> (Error?) -> Void {
return { error in
if let error {
continuation.resume(throwing: error)
} else {
continuation.resume(returning: ())
}
}
}
private func completion<T: Sendable>(_ continuation: UnsafeContinuation<T, Error>) -> (T?, Error?) -> Void {
return { value, error in
if let error {
continuation.resume(throwing: error)
} else if let value {
continuation.resume(returning: value)
}
}
}