In general, an app's back- and front-ends should be separated, allowing for background processing of tasks.
If it makes sense for an app to complete background tasks after the window is closed (such as sending an email or downloading a file), the tasks should be completed soon after the window is closed. If the app performs repeat background tasks (such as checking for new mail), the background tasks should be handled by a separate daemon.
It is not desirable for an app window to simply minimize rather than close when the user attempts to close it. Instead, the app window should indeed close. If it makes sense to continue a process in the background (such as downloading/transferring, playing music, or executing a terminal command) the app backend should continue with the task and close when the task is finished. If it's not immediately apparent that the process has completed (as with the file download/transfer or terminal command), the app may show a notification informing the user that the process has completed. If it is apparent, as with the music, no notification is necessary.
If the user re-opens the app while the background process is still executing, the app should be exactly where it would be if the window had been open the whole time. For example, the terminal should show any terminal output, the music player should be on the same page it was when closed, and the browser should come back to the page it was on previously. For more details, see the discussion of app state on a Normal Launch.