"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var hook_1 = require("./hook");
var SyncHook = /** @class */ (function (_super) {
    tslib_1.__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 = tslib_1.__values(this.getListeners()), _c = _b.next(); !_c.done; _c = _b.next()) {
                var listener = _c.value;
                listener.callback.apply(listener, tslib_1.__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_1.Hook));
exports.SyncHook = SyncHook;
