/** * Helper class to asynchronously wait until certain promises are resolved * * @example * ```ts * // myService * private loaded: Deferred = new Deferred(); * // after something was done * this.loaded.resolve(); * * // myOtherService or myComponent * await this.myService.loaded; * // * ``` */ export class Deferred { /** * The promise to wait for */ public readonly promise: Promise; /** * custom resolve function */ private _resolve: () => void; /** * Creates the promise and overloads the resolve function */ public constructor() { this.promise = new Promise(resolve => { this.resolve = resolve; }); } /** * Entry point for the resolve function */ public resolve(): void { this._resolve(); } }