@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
69 lines • 2.38 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchemaLoadingController = void 0;
/**
* Assists in tracking the loading progress of Schemas and SchemaItems. An instance of this
* class is set in Schema and SchemaItem instances.
* @internal
*/
class SchemaLoadingController {
_complete;
_inProgress;
_promise;
/**
* Indicates of the Schema or SchemaItem has been fully loaded.
*/
get isComplete() {
return this._complete;
}
/**
* Marks that a Schema or SchemaItem has been fully loaded.
*/
set isComplete(value) {
this._complete = value;
}
/**
* Indicates that the loading of a Schema or SchemaItem is still in progress
*/
get inProgress() {
return this._inProgress;
}
/**
* Initializes a new SchemaLoadingController instance.
*/
constructor() {
this._complete = false;
this._inProgress = false;
}
/**
* Call this method when starting to load a Schema or SchemaItem
* @param promise The promise used to update the controller state when the promise is resolved.
*/
start(promise) {
this._inProgress = true;
promise.then(() => {
this._complete = true;
this._inProgress = false;
}).catch(() => {
// Errors are handled when wait() is called. This catch prevents unhandled rejection warnings.
this._complete = false;
this._inProgress = false;
});
this._promise = promise;
}
/**
* Waits on the Promise given in SchemaLoadingController.start().
* @returns A Promised that can be awaited while the Schema or SchemaItem is being loaded.
*/
async wait() {
if (!this._promise)
throw new Error("LoadingController 'start' must be called before 'wait'");
return this._promise;
}
}
exports.SchemaLoadingController = SchemaLoadingController;
//# sourceMappingURL=SchemaLoadingController.js.map