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 23:03:21 +04:00 committed by GitHub
parent e061d00afc
commit 31635e59d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

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()