From 37def4245ec3bf34b27109ee75e3534808311460 Mon Sep 17 00:00:00 2001 From: Carlo Morgenstern Date: Sun, 24 Oct 2021 17:48:49 +0200 Subject: [PATCH] CardCreator: Updated ensureInit to proper singleton --- create-card.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/create-card.js b/create-card.js index 939c4e9..490ab36 100644 --- a/create-card.js +++ b/create-card.js @@ -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() {