From 7759c72a76e87889821177a3c1d0f81cca2b7ddb Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Tue, 14 Jun 2022 11:31:31 -0400 Subject: [PATCH] Don't use dispatchMain (#123) --- Sources/tart/Commands/Run.swift | 40 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index 7785065..3952b6c 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -37,23 +37,7 @@ struct Run: AsyncParsableCommand { let vmDir = try VMStorageLocal().open(name) vm = try VM(vmDir: vmDir) - await withThrowingTaskGroup(of: Void.self) { group in - if vnc { - group.addTask(operation: { - do { - print("Waiting for the VM to boot...") - let resolvedIP = try await IP.resolveIP(vm!.config, secondsToWait: 60) - guard let ip = resolvedIP else { - throw IPNotFound() - } - let url = URL(string: "vnc://\(ip)")! - print("Opening \(url)") - NSWorkspace.shared.open(url) - } catch { - print("Failed to get an IP for screen sharing: \(error)") - } - }) - } + try await withThrowingTaskGroup(of: Void.self) { group in group.addTask { do { try await vm!.run(recovery) @@ -69,12 +53,26 @@ struct Run: AsyncParsableCommand { Foundation.exit(1) } } - - if noGraphics || vnc { - dispatchMain() - } else { + if vnc { + group.addTask(operation: { + do { + print("Waiting for the VM to boot...") + let resolvedIP = try await IP.resolveIP(vm!.config, secondsToWait: 60) + guard let ip = resolvedIP else { + throw IPNotFound() + } + let url = URL(string: "vnc://\(ip)")! + print("Opening \(url)") + NSWorkspace.shared.open(url) + } catch { + print("Failed to get an IP for screen sharing: \(error)") + } + }) + } else if !noGraphics { runUI() } + + try await group.waitForAll() } }