提交 ae6a270a 编写于 作者: B Benjamin Pasero

use queued sender for ext host communication

上级 844484aa
......@@ -10,6 +10,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { ExtensionHostMain, IInitData, exit } from 'vs/workbench/node/extensionHostMain';
import { create as createIPC, IMainProcessExtHostIPC } from 'vs/platform/extensions/common/ipcRemoteCom';
import marshalling = require('vs/base/common/marshalling');
import { createQueuedSender } from 'vs/base/node/processes';
interface IRendererConnection {
remoteCom: IMainProcessExtHostIPC;
......@@ -22,6 +23,9 @@ let onTerminate = function () {
exit();
};
// Utility to not flood the process.send() with messages if it is busy catching up
const queuedSender = createQueuedSender(process);
function connectToRenderer(): TPromise<IRendererConnection> {
return new TPromise<IRendererConnection>((c, e) => {
const stats: number[] = [];
......@@ -32,7 +36,7 @@ function connectToRenderer(): TPromise<IRendererConnection> {
let msg = marshalling.parse(raw);
const remoteCom = createIPC(data => {
process.send(data);
queuedSender.send(data);
stats.push(data.length);
});
......@@ -92,13 +96,13 @@ function connectToRenderer(): TPromise<IRendererConnection> {
}, 1000);
// Tell the outside that we are initialized
process.send('initialized');
queuedSender.send('initialized');
c({ remoteCom, initData: msg });
});
// Tell the outside that we are ready to receive messages
process.send('ready');
queuedSender.send('ready');
});
}
......
......@@ -29,6 +29,7 @@ import { ExtensionScanner, MessagesCollector } from 'vs/workbench/node/extension
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
import Event, { Emitter } from 'vs/base/common/event';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { createQueuedSender, IQueuedSender } from 'vs/base/node/processes';
export const EXTENSION_LOG_BROADCAST_CHANNEL = 'vscode:extensionLog';
export const EXTENSION_ATTACH_BROADCAST_CHANNEL = 'vscode:extensionAttach';
......@@ -47,6 +48,7 @@ export interface ILogEntry {
export class ExtensionHostProcessWorker {
private initializeExtensionHostProcess: TPromise<ChildProcess>;
private extensionHostProcessHandle: ChildProcess;
private extensionHostProcessQueuedSender: IQueuedSender;
private extensionHostProcessReady: boolean;
private initializeTimer: number;
......@@ -126,6 +128,7 @@ export class ExtensionHostProcessWorker {
// Run Extension Host as fork of current process
this.extensionHostProcessHandle = fork(URI.parse(require.toUrl('bootstrap')).fsPath, ['--type=extensionHost'], opts);
this.extensionHostProcessQueuedSender = createQueuedSender(this.extensionHostProcessHandle);
// Notify debugger that we are ready to attach to the process if we run a development extension
if (this.isExtensionDevelopmentHost && port) {
......@@ -221,7 +224,7 @@ export class ExtensionHostProcessWorker {
workspaceStoragePath: this.storageService.getStoragePath(StorageScope.WORKSPACE),
extensions: extensionDescriptors
});
this.extensionHostProcessHandle.send(initPayload);
this.extensionHostProcessQueuedSender.send(initPayload);
});
}
......@@ -351,9 +354,9 @@ export class ExtensionHostProcessWorker {
public send(msg: any): void {
if (this.extensionHostProcessReady) {
this.extensionHostProcessHandle.send(msg);
this.extensionHostProcessQueuedSender.send(msg);
} else if (this.initializeExtensionHostProcess) {
this.initializeExtensionHostProcess.done(p => p.send(msg));
this.initializeExtensionHostProcess.done(() => this.extensionHostProcessQueuedSender.send(msg));
} else {
this.unsentMessages.push(msg);
}
......@@ -363,7 +366,7 @@ export class ExtensionHostProcessWorker {
this.terminating = true;
if (this.extensionHostProcessHandle) {
this.extensionHostProcessHandle.send({
this.extensionHostProcessQueuedSender.send({
type: '__$terminate'
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册