ajsfw
Version:
Ajs Framework
60 lines (59 loc) • 2.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var ServiceAsyncInit = (function () {
function ServiceAsyncInit() {
this.__initialized = false;
this.__initializing = false;
this.__onInitializedPromiseResolvers = [];
this.__onInitializedPromiseRejectors = [];
}
Object.defineProperty(ServiceAsyncInit.prototype, "initialized", {
get: function () { return this.__initialized; },
enumerable: true,
configurable: true
});
ServiceAsyncInit.prototype.initialize = function () {
var _this = this;
if (this.__initialized) {
return Promise.resolve();
}
var initPromise = new Promise(function (resolve, reject) {
_this.__registerResolverRejector(resolve, reject);
});
if (this.__initializing) {
return initPromise;
}
this.__initializing = true;
this._onInitializeAsync()
.then(function () {
_this.__initDone();
})
.catch(function (reason) {
_this.__initFail(reason);
});
return initPromise;
};
ServiceAsyncInit.prototype.__registerResolverRejector = function (resolve, reject) {
this.__onInitializedPromiseResolvers.push(resolve);
this.__onInitializedPromiseRejectors.push(reject);
};
ServiceAsyncInit.prototype.__initDone = function () {
this.__initialized = true;
for (var _i = 0, _a = this.__onInitializedPromiseResolvers; _i < _a.length; _i++) {
var resolver = _a[_i];
resolver();
}
this.__onInitializedPromiseResolvers = [];
this.__onInitializedPromiseRejectors = [];
};
ServiceAsyncInit.prototype.__initFail = function (reason) {
for (var _i = 0, _a = this.__onInitializedPromiseRejectors; _i < _a.length; _i++) {
var rejector = _a[_i];
rejector(reason);
}
this.__onInitializedPromiseResolvers = [];
this.__onInitializedPromiseRejectors = [];
};
return ServiceAsyncInit;
}());
exports.ServiceAsyncInit = ServiceAsyncInit;