"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const AsyncWorker_1 = require("../../../../AsyncWorker");
const Holder_1 = require("../../../../Class/Holder");
const RemotePort_1 = require("../../../../RemotePort");
const UCGJEE_1 = require("../../../../types/interface/UCGJEE");
const wrap_1 = require("../../../../wrap");
const _ids_1 = require("../../../_ids");
class RemoteGraph extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['opt'],
            fo: ['graph'],
            i: ['message'],
            o: ['message'],
        }, {
            output: {
                graph: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_REMOTE_GRAPH, 'close');
        this.addListener('take_err', () => {
            //
        });
        this.addListener('take_caught_err', () => {
            //
        });
    }
    f({ opt }, done) {
        const port = {
            send: (data) => {
                this._output.message.push(data);
            },
            onmessage(data) { },
            onerror() { },
        };
        this._port = port;
        const remote_port = new RemotePort_1.RemotePort(this.__system, port);
        this._remote_port = remote_port;
        const __ = UCGJEE_1.UCGJEE;
        const $graph = (0, AsyncWorker_1.AsyncWorker)(remote_port, __);
        const graph = (0, wrap_1.$wrap)(this.__system, $graph, __);
        done({ graph });
    }
    d() {
        if (this._remote_port) {
            this._remote_port.close();
            this._remote_port = undefined;
            this._forward_empty('graph');
        }
    }
    async onIterDataInputData(name, data) {
        // console.log('Remote', 'onIterDataInputData', name, _data)
        super.onIterDataInputData(name, data);
        if (name === 'message') {
            this._port.onmessage(data);
            this._backward('message');
        }
    }
}
exports.default = RemoteGraph;
//# sourceMappingURL=index.js.map