Actually, before migrating to strict concurrency I used RunLoop
.
func run() {
let renderer = /*create renderer*/
var quit = false
while !quit {
quit = fetchEvents()
updateState()
_ = RunLoop.current.run(mode: .default, before: .now)
render()
SDL_RenderPresent(renderer) // if VSYNC is ON, it will block main thread
}
}
Things like Timer
work as expected, but tasks isolated to main actor will never be executed.
func actionHandler() {
// won't execute
Task { @MainActor in
try await Task.sleep(for: .seconds(0.5))
self.doNextAction()
}
}
BTW, I'm talking about Windows here. Not sure how much Windows implementation of RunLoop
is different from the version for Darwin.