Skip to content

Commit

Permalink
lifecycle - onShutdown => onDidShutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Apr 6, 2021
1 parent ee4b092 commit f250472
Show file tree
Hide file tree
Showing 22 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/web.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class BrowserMain extends Disposable {
}
}));
this._register(workbench.onWillShutdown(() => storageService.close()));
this._register(workbench.onShutdown(() => this.dispose()));
this._register(workbench.onDidShutdown(() => this.dispose()));
}

private async initServices(): Promise<{ serviceCollection: ServiceCollection, configurationService: IWorkbenchConfigurationService, logService: ILogService, storageService: BrowserStorageService }> {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/browser/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class Workbench extends Layout {
private readonly _onWillShutdown = this._register(new Emitter<WillShutdownEvent>());
readonly onWillShutdown = this._onWillShutdown.event;

private readonly _onShutdown = this._register(new Emitter<void>());
readonly onShutdown = this._onShutdown.event;
private readonly _onDidShutdown = this._register(new Emitter<void>());
readonly onDidShutdown = this._onDidShutdown.event;

constructor(
parent: HTMLElement,
Expand Down Expand Up @@ -240,8 +240,8 @@ export class Workbench extends Layout {
// Lifecycle
this._register(lifecycleService.onBeforeShutdown(event => this._onBeforeShutdown.fire(event)));
this._register(lifecycleService.onWillShutdown(event => this._onWillShutdown.fire(event)));
this._register(lifecycleService.onShutdown(() => {
this._onShutdown.fire();
this._register(lifecycleService.onDidShutdown(() => {
this._onDidShutdown.fire();
this.dispose();
}));

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/debug/browser/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class DebugService implements IDebugService {
this.taskRunner = this.instantiationService.createInstance(DebugTaskRunner);

this.toDispose.push(this.fileService.onDidFilesChange(e => this.onFileChanges(e)));
this.toDispose.push(this.lifecycleService.onShutdown(this.dispose, this));
this.toDispose.push(this.lifecycleService.onDidShutdown(this.dispose, this));

this.toDispose.push(this.extensionHostDebugService.onAttachSession(event => {
const session = this.model.getSession(event.sessionId, true);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/debug/browser/debugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class DebugSession implements IDebugSession {
const toDispose: IDisposable[] = [];
toDispose.push(this.repl.onDidChangeElements(() => this._onDidChangeREPLElements.fire()));
if (lifecycleService) {
toDispose.push(lifecycleService.onShutdown(() => {
toDispose.push(lifecycleService.onDidShutdown(() => {
this.shutdown();
dispose(toDispose);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class KeymapExtensions extends Disposable implements IWorkbenchContributi
@ITelemetryService private readonly telemetryService: ITelemetryService,
) {
super();
this._register(lifecycleService.onShutdown(() => this.dispose()));
this._register(lifecycleService.onDidShutdown(() => this.dispose()));
this._register(instantiationService.invokeFunction(onExtensionChanged)((identifiers => {
Promise.all(identifiers.map(identifier => this.checkForOtherKeymaps(identifier)))
.then(undefined, onUnexpectedError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class TextFileEditorTracker extends Disposable implements IWorkbenchContr
this._register(this.hostService.onDidChangeFocus(hasFocus => hasFocus ? this.reloadVisibleTextFileEditors() : undefined));

// Lifecycle
this.lifecycleService.onShutdown(() => this.dispose());
this.lifecycleService.onDidShutdown(() => this.dispose());
}

//#region Text File: Ensure every dirty text and untitled file is opened in an editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class DirtyFilesIndicator extends Disposable implements IWorkbenchContrib
this._register(this.workingCopyService.onDidChangeDirty(workingCopy => this.onWorkingCopyDidChangeDirty(workingCopy)));

// Lifecycle
this.lifecycleService.onShutdown(() => this.dispose());
this.lifecycleService.onDidShutdown(() => this.dispose());
}

private onWorkingCopyDidChangeDirty(workingCopy: IWorkingCopy): void {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/output/browser/outputServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class OutputService extends Disposable implements IOutputService, ITextMo
this.setActiveChannel(channels && channels.length > 0 ? this.getChannel(channels[0].id) : undefined);
}

this._register(this.lifecycleService.onShutdown(() => this.dispose()));
this._register(this.lifecycleService.onDidShutdown(() => this.dispose()));
}

provideTextContent(resource: URI): Promise<ITextModel> | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class TelemetryContribution extends Disposable implements IWorkbenchContr
this._register(textFileService.files.onDidSave(e => this.onTextFileModelSaved(e)));

// Lifecycle
this._register(lifecycleService.onShutdown(() => this.dispose()));
this._register(lifecycleService.onDidShutdown(() => this.dispose()));
}

private onTextFileModelResolved(e: ITextFileResolveEvent): void {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/watermark/browser/watermark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class WatermarkContribution extends Disposable implements IWorkbenchContr
}

private registerListeners(): void {
this.lifecycleService.onShutdown(() => this.dispose());
this.lifecycleService.onDidShutdown(() => this.dispose());

this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(WORKBENCH_TIPS_ENABLED_KEY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class WelcomePage extends Disposable {

) {
super();
this._register(lifecycleService.onShutdown(() => this.dispose()));
this._register(lifecycleService.onDidShutdown(() => this.dispose()));

const recentlyOpened = this.workspacesService.getRecentlyOpened();
const installedExtensions = this.instantiationService.invokeFunction(getInstalledExtensions);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/electron-sandbox/shared.desktop.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export abstract class SharedDesktopMain extends Disposable {

// Workbench Lifecycle
this._register(workbench.onWillShutdown(event => event.join(storageService.close(), 'join.closeStorage')));
this._register(workbench.onShutdown(() => this.dispose()));
this._register(workbench.onDidShutdown(() => this.dispose()));
}

protected abstract registerFileSystemProviders(fileService: IFileService, logService: ILogService, nativeHostService: INativeHostService): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class RemoteExtensionHost extends Disposable implements IExtensionHost {
this._hasLostConnection = false;
this._terminating = false;

this._register(this._lifecycleService.onShutdown(reason => this.dispose()));
this._register(this._lifecycleService.onDidShutdown(() => this.dispose()));

const devOpts = parseExtensionDevOptions(this._environmentService);
this._isExtensionDevHost = devOpts.isExtensionDevHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class LocalProcessExtensionHost implements IExtensionHost {

this._toDispose.add(this._onExit);
this._toDispose.add(this._lifecycleService.onWillShutdown(e => this._onWillShutdown(e)));
this._toDispose.add(this._lifecycleService.onShutdown(reason => this.terminate()));
this._toDispose.add(this._lifecycleService.onDidShutdown(reason => this.terminate()));
this._toDispose.add(this._extensionHostDebugService.onClose(event => {
if (this._isExtensionDevHost && this._environmentService.debugExtensionHost.debugId === event.sessionId) {
this._nativeHostService.closeWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ export class BrowserLifecycleService extends AbstractLifecycleService {
return;
}

// No Veto: continue with Will Shutdown
// No Veto: continue with willShutdown
this._onWillShutdown.fire({
join(promise, id) {
logService.error(`[lifecycle] Long running operations during shutdown are unsupported in the web (id: ${id})`);
},
reason: ShutdownReason.QUIT
});

// Finally end with Shutdown event
this._onShutdown.fire();
// Finally end with didShutdown
this._onDidShutdown.fire();
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/vs/workbench/services/lifecycle/common/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,22 @@ export interface ILifecycleService {
readonly onBeforeShutdown: Event<BeforeShutdownEvent>;

/**
* Fired when no client is preventing the shutdown from happening (from onBeforeShutdown).
* Can be used to save UI state even if that is long running through the WillShutdownEvent#join()
* method.
* Fired when no client is preventing the shutdown from happening (from `onBeforeShutdown`).
*
* This event can be joined with a long running operation via `WillShutdownEvent#join()` to
* handle long running shutdown operations.
*
* The event carries a shutdown reason that indicates how the shutdown was triggered.
*/
readonly onWillShutdown: Event<WillShutdownEvent>;

/**
* Fired when the shutdown is about to happen after long running shutdown operations
* have finished (from onWillShutdown). This is the right place to dispose resources.
* have finished (from `onWillShutdown`).
*
* This event should be used to dispose resources.
*/
readonly onShutdown: Event<void>;
readonly onDidShutdown: Event<void>;

/**
* Returns a promise that resolves when a certain lifecycle phase
Expand All @@ -185,7 +188,7 @@ export const NullLifecycleService: ILifecycleService = {

onBeforeShutdown: Event.None,
onWillShutdown: Event.None,
onShutdown: Event.None,
onDidShutdown: Event.None,

phase: LifecyclePhase.Restored,
startupKind: StartupKind.NewWindow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export abstract class AbstractLifecycleService extends Disposable implements ILi
protected readonly _onWillShutdown = this._register(new Emitter<WillShutdownEvent>());
readonly onWillShutdown = this._onWillShutdown.event;

protected readonly _onShutdown = this._register(new Emitter<void>());
readonly onShutdown = this._onShutdown.event;
protected readonly _onDidShutdown = this._register(new Emitter<void>());
readonly onDidShutdown = this._onDidShutdown.event;

protected _startupKind: StartupKind = StartupKind.NewWindow;
get startupKind(): StartupKind { return this._startupKind; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export class NativeLifecycleService extends AbstractLifecycleService {
// trigger onWillShutdown events and joining
await this.handleWillShutdown(reply.reason);

// trigger onShutdown event now that we know we will quit
this._onShutdown.fire();
// trigger onDidShutdown event now that we know we will quit
this._onDidShutdown.fire();

// acknowledge to main side
ipcRenderer.send(reply.replyChannel, windowId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
protected registerListeners(): void {

// Lifecycle
this.lifecycleService.onShutdown(() => this.dispose());
this.lifecycleService.onDidShutdown(() => this.dispose());
}

//#region text file read / write / create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE
this._register(this.workingCopyFileService.onDidRunWorkingCopyFileOperation(e => this.onDidRunWorkingCopyFileOperation(e)));

// Lifecycle
this.lifecycleService.onShutdown(() => this.dispose());
this.lifecycleService.onDidShutdown(() => this.dispose());
}

private onDidFilesChange(e: FileChangesEvent): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class FileWorkingCopyManager<T extends IFileWorkingCopyModel> extends Dis
this._register(this.workingCopyFileService.onDidRunWorkingCopyFileOperation(e => this.onDidRunWorkingCopyFileOperation(e)));

// Lifecycle
this.lifecycleService.onShutdown(() => this.dispose());
this.lifecycleService.onDidShutdown(() => this.dispose());
}

//#region Resolve from file changes
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/test/browser/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ export class TestLifecycleService implements ILifecycleService {
get onWillShutdown(): Event<WillShutdownEvent> { return this._onWillShutdown.event; }

private readonly _onShutdown = new Emitter<void>();
get onShutdown(): Event<void> { return this._onShutdown.event; }
get onDidShutdown(): Event<void> { return this._onShutdown.event; }

async when(): Promise<void> { }

Expand Down

0 comments on commit f250472

Please sign in to comment.