Skip to content

Commit

Permalink
lifecycle - adopt the onWillKill event
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 9, 2021
1 parent ca19d14 commit 6780770
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
import { Promises } from 'vs/base/common/async';
import { ExtensionHostStarter, IPartialLogService } from 'vs/platform/extensions/node/extensionHostStarter';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { ILogService } from 'vs/platform/log/common/log';
Expand All @@ -12,24 +12,24 @@ export class DirectMainProcessExtensionHostStarter extends ExtensionHostStarter

constructor(
@ILogService logService: IPartialLogService,
@ILifecycleMainService lifecycleMainService: ILifecycleMainService,
@IEnvironmentMainService environmentService: IEnvironmentMainService,
@ILifecycleMainService lifecycleMainService: ILifecycleMainService
) {
super(logService);

// Abnormal shutdown: terminate extension hosts asap
lifecycleMainService.onWillKill(() => {
for (const [, extHost] of this._extHosts) {
extHost.kill();
}
});

// Normal shutdown: gracefully await extension host shutdowns
lifecycleMainService.onWillShutdown((e) => {
if (environmentService.extensionTestsLocationURI) {
// extension testing => don't wait for graceful shutdown
for (const [, extHost] of this._extHosts) {
extHost.kill();
}
} else {
const exitPromises: Promise<void>[] = [];
for (const [, extHost] of this._extHosts) {
exitPromises.push(extHost.waitForExit(6000));
}
e.join(Promise.all(exitPromises).then(() => { }));
const exitPromises: Promise<void>[] = [];
for (const [, extHost] of this._extHosts) {
exitPromises.push(extHost.waitForExit(6000));
}
e.join(Promises.settled(exitPromises).then(() => { }));
});
}

Expand Down

0 comments on commit 6780770

Please sign in to comment.