CardCreator: Updated ensureInit to proper singleton
This commit is contained in:
parent
3a9e4d7502
commit
37def4245e
1 changed files with 4 additions and 7 deletions
|
@ -116,7 +116,7 @@ class CardCreator {
|
||||||
*/
|
*/
|
||||||
constructor(xivApiKey = undefined) {
|
constructor(xivApiKey = undefined) {
|
||||||
this.xivApiKey = typeof xivApiKey === 'string' && xivApiKey !== '' ? xivApiKey : undefined;
|
this.xivApiKey = typeof xivApiKey === 'string' && xivApiKey !== '' ? xivApiKey : undefined;
|
||||||
this.isInit = false;
|
this.initPromise = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,12 +143,9 @@ class CardCreator {
|
||||||
* @returns {Promise} A promise representing the initialization state of this generator.
|
* @returns {Promise} A promise representing the initialization state of this generator.
|
||||||
*/
|
*/
|
||||||
async ensureInit() {
|
async ensureInit() {
|
||||||
if (this.isInit) {
|
if (this.initPromise == null) this.initPromise = this.init();
|
||||||
return;
|
|
||||||
}
|
await this.initPromise;
|
||||||
|
|
||||||
await this.init();
|
|
||||||
this.isInit = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
|
Loading…
Reference in a new issue