Last active
August 29, 2015 14:28
-
-
Save blink1073/f0c6701de6095b6a75ed to your computer and use it in GitHub Desktop.
Services Base Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Service { | |
constructor() { | |
this._onReady = new Promise<void>((resolve, reject) => { | |
this._finishInit = resolve; | |
}); | |
} | |
/** | |
* Promise fullfilled when the object is initialized. | |
*/ | |
get onReady(): Promise<void> { | |
return this._onReady; | |
} | |
/** | |
* Handle initialization, fulfilling the onReady promise on the first call. | |
*/ | |
protected _initReady(): void { | |
var callback = this._finishInit; | |
if (callback) { | |
this._finishInit = null; | |
callback(); | |
} | |
} | |
private _onReady: Promise<void> = null; | |
private _finishInit: () => void = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment