提交 32c6a6a2 编写于 作者: S Sandeep Somavarapu

SharedProcess: Create returns a promise resolved when it is available to connect

上级 148c8d07
......@@ -128,7 +128,10 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
debugPort: envService.isBuilt ? null : 5871
};
const sharedProcess = spawnSharedProcess(initData, options);
let sharedProcessDisposable;
spawnSharedProcess(initData, options).done(disposable => {
sharedProcessDisposable = disposable;
});
// Make sure we associate the program with the app user model id
// This will help Windows to associate the running program with
......@@ -144,7 +147,9 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
mainIpcServer = null;
}
sharedProcess.dispose();
if (sharedProcessDisposable) {
sharedProcessDisposable.dispose();
}
if (windowsMutex) {
windowsMutex.release();
......
......@@ -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;
}
\ No newline at end of file
......@@ -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);
\ No newline at end of file
setupIPC(process.env['VSCODE_SHARED_IPC_HOOK'])
.then(server => handshake()
.then(data => main(server, data))
.then(() => setupPlanB(process.env['VSCODE_PID']))
.done(null, quit));
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册