My Cocoa application wants to disconnect a network client before quitting. Seems pretty straightforward, but the operation is async throws
.
So far, I have this to handle termination:
@MainActor func applicationWillTerminate(_: Notification) {
Task {
try! await viewController.tearDownClient()
}
}
This doesn't actually work because the Task
gets scheduled to run later. The application is currently about to terminate, so there is no "later" for the Task
to run in.
I have run into a similar situation with the actual view controller itself:
deinit {
Task {
try! await tearDownClient()
}
}
This doesn't work for similar reasons.
I suppose what I need is a way to block on the completion of these asynchronous operations. I realize that is an undesired operation most of the time, but I don't see another way.