mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-03 23:06:49 +01:00
SharedProcess: Create returns a promise resolved when it is available to connect
This commit is contained in:
@@ -8,6 +8,7 @@ import URI from 'vs/base/common/uri';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { ParsedArgs } from 'vs/platform/environment/node/argv';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
|
||||
export interface ISharedProcessInitData {
|
||||
args: ParsedArgs;
|
||||
@@ -36,34 +37,40 @@ function _spawnSharedProcess(initData: ISharedProcessInitData, options: ISharedP
|
||||
|
||||
const result = cp.fork(boostrapPath, ['--type=SharedProcess'], { env, execArgv });
|
||||
|
||||
// handshake
|
||||
result.once('message', () => result.send(initData));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function spawnSharedProcess(initData: ISharedProcessInitData, options: ISharedProcessOptions = {}): IDisposable {
|
||||
export function spawnSharedProcess(initData: ISharedProcessInitData, options: ISharedProcessOptions = {}): TPromise<IDisposable> {
|
||||
let spawnCount = 0;
|
||||
let child: cp.ChildProcess;
|
||||
|
||||
let promise: TPromise<IDisposable>;
|
||||
|
||||
const spawn = () => {
|
||||
if (++spawnCount > 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
child = _spawnSharedProcess(initData, options);
|
||||
promise = new TPromise<IDisposable>((c, e) => {
|
||||
// handshake
|
||||
child.once('message', () => {
|
||||
child.send(initData);
|
||||
c({
|
||||
dispose: () => {
|
||||
if (child) {
|
||||
child.removeListener('exit', spawn);
|
||||
child.kill();
|
||||
child = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
child.on('exit', spawn);
|
||||
};
|
||||
|
||||
spawn();
|
||||
|
||||
return {
|
||||
dispose: () => {
|
||||
if (child) {
|
||||
child.removeListener('exit', spawn);
|
||||
child.kill();
|
||||
child = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
return promise;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ function setupIPC(hook: string): TPromise<Server> {
|
||||
} catch (e) {
|
||||
return TPromise.wrapError(new Error('Error deleting the shared ipc hook.'));
|
||||
}
|
||||
|
||||
|
||||
return setup(false);
|
||||
}
|
||||
);
|
||||
@@ -155,7 +155,8 @@ function handshake(): TPromise<ISharedProcessInitData> {
|
||||
});
|
||||
}
|
||||
|
||||
TPromise.join<any>([setupIPC(process.env['VSCODE_SHARED_IPC_HOOK']), handshake()])
|
||||
.then(r => main(r[0], r[1]))
|
||||
.then(() => setupPlanB(process.env['VSCODE_PID']))
|
||||
.done(null, quit);
|
||||
setupIPC(process.env['VSCODE_SHARED_IPC_HOOK'])
|
||||
.then(server => handshake()
|
||||
.then(data => main(server, data))
|
||||
.then(() => setupPlanB(process.env['VSCODE_PID']))
|
||||
.done(null, quit));
|
||||
Reference in New Issue
Block a user