"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtensionConnection = exports.IInterProcessConnectionService = void 0;
const events_1 = require("@opensumi/events");
exports.IInterProcessConnectionService = Symbol('IInterProcessConnectionService');
/**
 * Definition of the communication layer between the ext process and the main process
 */
class ExtensionConnection {
    constructor(id, proxy, dispose) {
        this.id = id;
        this.proxy = proxy;
        this.dispose = dispose;
        this.emitter = new events_1.EventEmitter();
    }
    send(data) {
        this.proxy.$sendMessage(this.id, data);
    }
    onMessage(cb) {
        return this.emitter.on('message', cb);
    }
    onceClose(cb) {
        return this.emitter.on('close', () => cb(-1, 'closed'));
    }
    close() {
        this.emitter.dispose();
        this.dispose();
    }
    readMessage(message) {
        this.emitter.emit('message', message);
    }
    fireClose() {
        this.emitter.emit('close');
    }
}
exports.ExtensionConnection = ExtensionConnection;
//# sourceMappingURL=connection.js.map