The main function needs to uiwait() or waitfor() something. After the wait it should check to see if output has been saved for it in some known location, and if so should return that. If not, then it needs to return some output anyhow or to error() deliberately or let the caller error by not returning something. (It might be given the go ahead to continue by the user choosing to close the figure instead of taking the proper callback.)
The callback that wants to allow the main to go ahead should uiresume() or should force the satisfaction of the event that main is waiting for.
Before returning, main might choose to delete the gui, hide it, or whatever is appropriate -- it is not mandatory to destroy the GUI when the constructing function returns.