import { __extends, __read, __spread, __values } from "tslib";
import { Hook } from "./hook";
var SyncHook = /** @class */ (function (_super) {
    __extends(SyncHook, _super);
    function SyncHook() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    SyncHook.prototype.lazyEmit = function (cb) {
        var listeners = this.getListeners();
        if (listeners.length === 0) {
            return;
        }
        var args = cb();
        return this.emit.apply(this, args);
    };
    SyncHook.prototype.emit = function () {
        var e_1, _a;
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        try {
            for (var _b = __values(this.getListeners()), _c = _b.next(); !_c.done; _c = _b.next()) {
                var listener = _c.value;
                listener.callback.apply(listener, __spread(args));
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_1) throw e_1.error; }
        }
    };
    return SyncHook;
}(Hook));
export { SyncHook };
