From 2020324ef53f8bfed28ffc3a89096184f85f2d77 Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Mon, 20 Jun 2022 10:28:10 -0400 Subject: [PATCH] Fixed --no-graphics (#132) Followup to #129 which broke CLI integration because `--no-graphics` option didn't wait for anything. --- Sources/tart/Commands/Run.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index 1b97ad6..7ec8c0c 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -37,9 +37,14 @@ struct Run: AsyncParsableCommand { let vmDir = try VMStorageLocal().open(name) vm = try VM(vmDir: vmDir) - Task { + let runTask = Task { do { try await vm!.run(recovery) + + // wait for VM to be in a final state before exit + while !(vm?.inFinalState ?? false) { + try await Task.sleep(nanoseconds: 1_000_000) + } Foundation.exit(0) } catch { @@ -65,12 +70,12 @@ struct Run: AsyncParsableCommand { } catch { print("Failed to get an IP for screen sharing: \(error)") } - while !(vm?.inFinalState ?? false) { - try await Task.sleep(nanoseconds: 1_000_000) - } } else if !noGraphics { runUI() } + + // wait for VM to get into a final state + try await runTask.value } private func runUI() {