CardCreator: Updated ensureInit to proper singleton

This commit is contained in:
Carlo Morgenstern 2021-10-24 17:48:49 +02:00
parent 3a9e4d7502
commit 37def4245e

View file

@ -116,7 +116,7 @@ class CardCreator {
*/
constructor(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.
*/
async ensureInit() {
if (this.isInit) {
return;
}
await this.init();
this.isInit = true;
if (this.initPromise == null) this.initPromise = this.init();
await this.initPromise;
}
async init() {