提交 8bff3955 编写于 作者: D Daniel Imms

Dispose of proxy listeners properly

上级 b7985f41
...@@ -109,10 +109,9 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape ...@@ -109,10 +109,9 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
env: request.shellLaunchConfig.env env: request.shellLaunchConfig.env
}; };
this._proxy.$createProcess(request.proxy.terminalId, shellLaunchConfigDto, request.cols, request.rows); this._proxy.$createProcess(request.proxy.terminalId, shellLaunchConfigDto, request.cols, request.rows);
// TODO: Dispose of this properly when the terminal/process dies request.proxy.onInput(data => this._proxy.$acceptProcessInput(request.proxy.terminalId, data));
this._toDispose.push(request.proxy.onInput(data => this._proxy.$acceptProcessInput(request.proxy.terminalId, data))); request.proxy.onResize((cols, rows) => this._proxy.$acceptProcessResize(request.proxy.terminalId, cols, rows));
this._toDispose.push(request.proxy.onResize((cols, rows) => this._proxy.$acceptProcessResize(request.proxy.terminalId, cols, rows))); request.proxy.onShutdown(() => this._proxy.$acceptProcessShutdown(request.proxy.terminalId));
this._toDispose.push(request.proxy.onShutdown(() => this._proxy.$acceptProcessShutdown(request.proxy.terminalId)));
} }
public $sendProcessTitle(terminalId: number, title: string): void { public $sendProcessTitle(terminalId: number, title: string): void {
......
...@@ -518,16 +518,17 @@ export enum ProcessState { ...@@ -518,16 +518,17 @@ export enum ProcessState {
} }
export interface ITerminalProcessExtHostProxy { export interface ITerminalProcessExtHostProxy extends IDisposable {
readonly terminalId: number; readonly terminalId: number;
emitData(data: string): void; emitData(data: string): void;
emitTitle(title: string): void; emitTitle(title: string): void;
emitPid(pid: number): void; emitPid(pid: number): void;
emitExit(exitCode: number): void; emitExit(exitCode: number): void;
onInput(listener: (data: string) => void): IDisposable;
onResize(listener: (cols: number, rows: number) => void): IDisposable; onInput(listener: (data: string) => void): void;
onShutdown(listener: () => void): IDisposable; onResize(listener: (cols: number, rows: number) => void): void;
onShutdown(listener: () => void): void;
} }
export interface ITerminalProcessExtHostRequest { export interface ITerminalProcessExtHostRequest {
......
...@@ -12,6 +12,8 @@ export class TerminalProcessExtHostProxy extends EventEmitter implements ITermin ...@@ -12,6 +12,8 @@ export class TerminalProcessExtHostProxy extends EventEmitter implements ITermin
// For ext host processes connected checks happen on the ext host // For ext host processes connected checks happen on the ext host
public connected: boolean = true; public connected: boolean = true;
private _disposables: IDisposable[] = [];
constructor( constructor(
public terminalId: number, public terminalId: number,
shellLaunchConfig: IShellLaunchConfig, shellLaunchConfig: IShellLaunchConfig,
...@@ -25,6 +27,11 @@ export class TerminalProcessExtHostProxy extends EventEmitter implements ITermin ...@@ -25,6 +27,11 @@ export class TerminalProcessExtHostProxy extends EventEmitter implements ITermin
this._terminalService.requestExtHostProcess(this, shellLaunchConfig, cols, rows); this._terminalService.requestExtHostProcess(this, shellLaunchConfig, cols, rows);
} }
public dispose(): void {
this._disposables.forEach(d => d.dispose());
this._disposables.length = 0;
}
public emitData(data: string): void { public emitData(data: string): void {
this.emit('message', { type: 'data', content: data } as IMessageFromTerminalProcess); this.emit('message', { type: 'data', content: data } as IMessageFromTerminalProcess);
} }
...@@ -39,6 +46,7 @@ export class TerminalProcessExtHostProxy extends EventEmitter implements ITermin ...@@ -39,6 +46,7 @@ export class TerminalProcessExtHostProxy extends EventEmitter implements ITermin
public emitExit(exitCode: number): void { public emitExit(exitCode: number): void {
this.emit('exit', exitCode); this.emit('exit', exitCode);
this.dispose();
} }
public send(message: IMessageToTerminalProcess): boolean { public send(message: IMessageToTerminalProcess): boolean {
...@@ -50,21 +58,21 @@ export class TerminalProcessExtHostProxy extends EventEmitter implements ITermin ...@@ -50,21 +58,21 @@ export class TerminalProcessExtHostProxy extends EventEmitter implements ITermin
return true; return true;
} }
public onInput(listener: (data: string) => void): IDisposable { public onInput(listener: (data: string) => void): void {
const outerListener = (data) => listener(data); const outerListener = (data) => listener(data);
this.on('input', outerListener); this.on('input', outerListener);
return toDisposable(() => this.removeListener('input', outerListener)); this._disposables.push(toDisposable(() => this.removeListener('input', outerListener)));
} }
public onResize(listener: (cols: number, rows: number) => void): IDisposable { public onResize(listener: (cols: number, rows: number) => void): void {
const outerListener = (cols, rows) => listener(cols, rows); const outerListener = (cols, rows) => listener(cols, rows);
this.on('resize', outerListener); this.on('resize', outerListener);
return toDisposable(() => this.removeListener('resize', outerListener)); this._disposables.push(toDisposable(() => this.removeListener('resize', outerListener)));
} }
public onShutdown(listener: () => void): IDisposable { public onShutdown(listener: () => void): void {
const outerListener = () => listener(); const outerListener = () => listener();
this.on('shutdown', outerListener); this.on('shutdown', outerListener);
return toDisposable(() => this.removeListener('shutdown', outerListener)); this._disposables.push(toDisposable(() => this.removeListener('shutdown', outerListener)));
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册