"use strict";
var ProcessService = (function () {
    function ProcessService() {
        var _this = this;
        this._listeners = [];
        _.each(ProcessService.PROCESS_EXIT_SIGNALS, function (signal) {
            process.on(signal, function () { return _this.executeAllCallbacks.apply(_this); });
        });
    }
    Object.defineProperty(ProcessService.prototype, "listenersCount", {
        get: function () {
            return this._listeners.length;
        },
        enumerable: true,
        configurable: true
    });
    ProcessService.prototype.attachToProcessExitSignals = function (context, callback) {
        var callbackToString = callback.toString();
        if (!_.some(this._listeners, function (listener) { return context === listener.context && callbackToString === listener.callback.toString(); })) {
            this._listeners.push({ context: context, callback: callback });
        }
    };
    ProcessService.prototype.executeAllCallbacks = function () {
        _.each(this._listeners, function (listener) {
            listener.callback.apply(listener.context);
        });
    };
    ProcessService.PROCESS_EXIT_SIGNALS = ["exit", "SIGINT", "SIGTERM"];
    return ProcessService;
}());
exports.ProcessService = ProcessService;
$injector.register("processService", ProcessService);
