Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promises are not working inside applicationShouldTerminate #157

Open
jeff-h opened this issue Aug 20, 2020 · 0 comments
Open

Promises are not working inside applicationShouldTerminate #157

jeff-h opened this issue Aug 20, 2020 · 0 comments

Comments

@jeff-h
Copy link
Contributor

jeff-h commented Aug 20, 2020

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:

func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
    print("applicationShouldTerminate")

     let promise = Promise<Void> { 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant