Skip to content

Instantly share code, notes, and snippets.

@blink1073
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blink1073/f0c6701de6095b6a75ed to your computer and use it in GitHub Desktop.
Save blink1073/f0c6701de6095b6a75ed to your computer and use it in GitHub Desktop.
Services Base Class
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