Skip to content

Commit

Permalink
More concurrency improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenbensley committed Sep 18, 2024
1 parent c3e4425 commit 9a7c4d9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions QueahSolver/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ struct ContentView: View {
Text("Ready to solve")
Button("Solve") {
solverState = .solving
// Solver.solve is synchronous, so we have to run it in a detached task to
// avoid starving the UI.
task = Task.detached(priority: .low) {
let eval = Solver.solve()
let gameValue = eval.evaluate(position: GamePosition.start)
let solution = SolutionFile(initialData: eval.encode())
// Update the UI from the MainActor
await MainActor.run {
gameValue = eval.evaluate(position: GamePosition.start)
solution = SolutionFile(initialData: eval.encode())
solverState = .solutionReady
self.gameValue = gameValue
self.solution = solution
self.solverState = .solutionReady
}
}
}
Expand Down

0 comments on commit 9a7c4d9

Please sign in to comment.