mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
proper await exit
This commit is contained in:
parent
187ccb8ec4
commit
954ce2c3f4
|
@ -69,7 +69,7 @@ async function connect(connectDriver: typeof connectElectronDriver, child: cp.Ch
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
const { client, driver } = await connectDriver(outPath, handlePath);
|
const { client, driver } = await connectDriver(outPath, handlePath);
|
||||||
return new Code(client, driver, logger);
|
return new Code(client, driver, logger, child?.pid);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (++errCount > 50) {
|
if (++errCount > 50) {
|
||||||
if (child) {
|
if (child) {
|
||||||
|
@ -254,7 +254,8 @@ export class Code {
|
||||||
constructor(
|
constructor(
|
||||||
private client: IDisposable,
|
private client: IDisposable,
|
||||||
driver: IDriver,
|
driver: IDriver,
|
||||||
readonly logger: Logger
|
readonly logger: Logger,
|
||||||
|
private readonly pid: number | undefined
|
||||||
) {
|
) {
|
||||||
this.driver = new Proxy(driver, {
|
this.driver = new Proxy(driver, {
|
||||||
get(target, prop, receiver) {
|
get(target, prop, receiver) {
|
||||||
|
@ -295,9 +296,27 @@ export class Code {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exit(): Promise<void> {
|
async exit(): Promise<void> {
|
||||||
const veto = await this.driver.exitApplication();
|
const exitPromise = this.driver.exitApplication();
|
||||||
if (veto === true) {
|
|
||||||
throw new Error('Code exit was blocked by a veto.');
|
// If we know the `pid`, use that to await the
|
||||||
|
// process to terminate (desktop).
|
||||||
|
const pid = this.pid;
|
||||||
|
if (typeof pid === 'number') {
|
||||||
|
await (async () => {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
process.kill(pid, 0); // throws an exception if the main process doesn't exist anymore.
|
||||||
|
await new Promise(c => setTimeout(c, 100));
|
||||||
|
} catch (error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise await the exit promise (web).
|
||||||
|
else {
|
||||||
|
await exitPromise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue