mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-22 12:50:29 -04:00
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
|
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
|
|
import { Event, Emitter } from 'vs/base/common/event';
|
|
|
|
export interface Sender {
|
|
send(channel: string, ...args: any[]): void;
|
|
}
|
|
|
|
export class Protocol implements IMessagePassingProtocol {
|
|
|
|
private listener: IDisposable;
|
|
|
|
private _onMessage: Event<any>;
|
|
get onMessage(): Event<any> { return this._onMessage; }
|
|
|
|
constructor(private sender: Sender, onMessageEvent: Event<any>) {
|
|
const emitter = new Emitter<any>();
|
|
onMessageEvent(msg => emitter.fire(msg));
|
|
this._onMessage = emitter.event;
|
|
}
|
|
|
|
send(message: any): void {
|
|
try {
|
|
this.sender.send('ipc:message', message);
|
|
} catch (e) {
|
|
// systems are going down
|
|
}
|
|
}
|
|
|
|
dispose(): void {
|
|
this.listener = dispose(this.listener);
|
|
}
|
|
} |