Don't swallow VZVirtualMachine.start() exceptions (#343)

* Don't swallow VZVirtualMachine.start() exceptions

* Rename task to startTask for clarity

* No need to use "self"
This commit is contained in:
Nikolay Edigaryev
2022-12-01 14:03:21 -05:00
committed by GitHub
parent e061d00afc
commit 31635e59d7
+7 -2
View File
@@ -219,7 +219,7 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
func run(_ recovery: Bool) async throws {
try network.run(sema)
DispatchQueue.main.sync {
let startTask = DispatchQueue.main.sync {
Task {
if #available(macOS 13, *) {
// new API introduced in Ventura
@@ -233,7 +233,12 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
}
}
await withTaskCancellationHandler(operation: {
try await withTaskCancellationHandler(operation: {
// Await on VZVirtualMachine.start() result
_ = try await startTask.value
// Wait for the VM to finish running
// or for the exit condition
sema.wait()
}, onCancel: {
sema.signal()