menuet icon indicating copy to clipboard operation
menuet copied to clipboard

defer functions doesn't execute when application exit

Open pelenthium opened this issue 5 years ago • 1 comments

Hi, thanks for this cool library, this awesome, and exactly what I need. But I see that we exit the application from native code, so it breaks golang spec - we can't execute defer functions :(

Can you please give a point on how to fix it?

pelenthium avatar Nov 08 '20 05:11 pelenthium

Interesting, thanks for the report.

This will probably require some experimentation. It may be that inside menuet.m's applicationShouldTerminate (https://github.com/caseymrm/menuet/blob/master/menuet.m#L225) we need to call back into go to clean up before returning NSTerminateNow.

Based on this: https://stackoverflow.com/questions/27629380/how-to-exit-a-go-program-honoring-deferred-calls this might be as simple as calling runtime.Goexit(), or maybe we would need to do the panic/recover mentioned in a later answer.

(This might also require making sure applicationWillTerminate is set to NO in your Info.plist, because nothing is ever easy.)

caseymrm avatar Nov 08 '20 15:11 caseymrm

Fixed by #20?

forfuncsake avatar Nov 19 '23 04:11 forfuncsake