"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Semifunctional_1 = require("../../../../../../../Class/Semifunctional");
const local_1 = require("../../../../../../../process/share/local");
const _ids_1 = require("../../../../../../_ids");
class LocalShareGraph extends Semifunctional_1.Semifunctional {
    constructor(system) {
        super({
            fi: ['opt', 'graph'],
            fo: ['id'],
            i: ['done'],
            o: [],
        }, {
            input: {
                graph: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_LOCAL_SHARE_GRAPH);
        this.__ = ['U'];
        this._connected = false;
        this._disconnect = () => {
            if (this._connected) {
                (0, local_1.stopBroadcastSource)(this._id);
                this._terminate();
                this._connected = false;
            }
        };
        this.addListener('destroy', () => {
            if (this._connected) {
                this._disconnect();
            }
        });
    }
    f({ opt, graph }, done) {
        const { id, terminate } = (0, local_1.shareLocalGraph)(graph);
        this._id = id;
        this._connected = true;
        this._terminate = terminate;
        done({ id });
    }
    d() {
        this._disconnect();
        this._id = undefined;
    }
    onIterDataInputData(name, data) {
        // if (name === 'done') {
        this._disconnect();
        this._forward_empty('id');
        this._backward('done');
        // }
    }
}
exports.default = LocalShareGraph;
//# sourceMappingURL=index.js.map