@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
61 lines • 2.01 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/**
* Assists in tracking the loading progress of Schemas and SchemaItems. An instance of this
* class is set in Schema and SchemaItem instances.
* @internal
*/
export 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;
void promise.then(() => {
this._complete = true;
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;
}
}
//# sourceMappingURL=SchemaLoadingController.js.map