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