onStop sync/async mix

The frontend/backend-contribution indicates that onStop is synchronous. However, WorkspaceServer’s onStop calls an asynchronous method to set the last used workspace.

Is there any garantee that the last workspace used will actually get written out to the filesystem, or is this a “fingers-crossed it finishes in time” situation?

I am curious if there is a way to finish asynchronous or long-running operations called within onStop. I want to store some data (which is an asynchronous operation) which can happen after the window closes, but before Theia exits. Is it possible to do this in Theia, Electron specifically?

[original thread by Matt Oster]

For the frontend we are relying on unload event. See https://github.com/theia-ide/theia/blob/master/packages/core/src/browser/frontend-application.ts#L159

It doesn’t run async afterwards.

There is onWillStop callback in which you can notify a user about unsaved changes: https://github.com/theia-ide/theia/blob/5156023a4b0c590b40485f82d5c798c6ef6f8dec/packages/core/src/browser/frontend-application.ts#L45-L50

and prevent closing