"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TrieListener = void 0;
const qlobber_1 = require("qlobber");
const abstract_listener_1 = require("./abstract-listener");
const util_1 = require("./util");
class TrieListener extends abstract_listener_1.AbstractListener {
    constructor(settings = {}) {
        super(settings);
        this.matcher = new qlobber_1.Qlobber({
            separator: settings.separator || '/',
            wildcard_one: settings.wildcardOne || '+',
            wildcard_some: settings.wildcardSome || '*',
        });
        this.emit('ready');
    }
    subscribe(topic, callback, done) {
        this._raiseIfClosed();
        this.matcher.add(topic, callback);
        (0, util_1.defer)(done);
    }
    publish(topic, message, options, done = () => { }) {
        this._raiseIfClosed();
        var cbs = this.matcher.match(topic);
        for (var i = 0; i < cbs.length; i++) {
            cbs[i](topic, message, options);
        }
        (0, util_1.defer)(done);
    }
    unsubscribe(topic, callback, done = () => { }) {
        this._raiseIfClosed();
        this.matcher.remove(topic, callback);
        (0, util_1.defer)(done);
    }
    close(done = () => { }) {
        this.matcher.clear();
        this.emit('closed');
        (0, util_1.defer)(done);
    }
}
exports.TrieListener = TrieListener;
//# sourceMappingURL=trie-listener.js.map