var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "../di/DISingleton"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.ObjectReference = void 0;
    var DISingleton_1 = require("../di/DISingleton");
    var ObjectReference = /** @class */ (function () {
        function ObjectReference(key, value) {
            this.key = key;
            this.value = value;
        }
        return ObjectReference;
    }());
    exports.ObjectReference = ObjectReference;
    var ReferenceService = /** @class */ (function () {
        function ReferenceService() {
            this.cache = {};
            this.id = 1;
        }
        ReferenceService.prototype.get = function (key) {
            return this.cache[key];
        };
        ReferenceService.prototype.put = function (item, ttl) {
            var _this = this;
            if (ttl === void 0) { ttl = 60; }
            var key = "k" + this.id++;
            var r = new ObjectReference(key, item);
            r.consume = function () {
                delete _this.cache[key];
                if (r.timeout) {
                    clearTimeout(r.timeout);
                }
                return r.value;
            };
            r.timeout = setTimeout(function () {
                r.timeout = 0;
                r.consume();
            }, ttl * 1000);
            this.cache[key] = r;
            return r;
        };
        ReferenceService = __decorate([
            DISingleton_1.default()
        ], ReferenceService);
        return ReferenceService;
    }());
    exports.default = ReferenceService;
});
//# sourceMappingURL=ReferenceService.js.map