Promises are not working inside applicationShouldTerminate
- Dominant language
- Objective-C
- Stars
- 3.8k
- Forks
- 316
- PR merge metrics
- No merged PRs in 30d
Description
I'd like to gracefully clean up some stuff using Promises when my app quits, so I've implemented `applicationShouldTerminate`. I'm definitely making it inside that method, but my promise code inside it only works when the app is quit via Command-Q. If I quit the app programmatically using `NSApplication.shared.terminate(self)` the `applicationShouldTerminate` does run, but the promises inside it do nothing.
I've tested this in a fresh project with the following:
```swift
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
print("applicationShouldTerminate")
let promise = Promise { fulfill, reject in
print("hello")
fulfill(())
}
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5)) {
NSApplication.shared.reply(toApplicationShouldTerminate: true)
}
return .terminateLater
}
```
When I quit with cmd-Q this works perfectly but when I quit the app programmatically using `NSApplication.shared.terminate(self)` it prints `applicationShouldTerminate` but nothing else happens and the app never quits.
Any suggestions?
Contributor guide
Assessment
This issue has not been assessed yet.