diff --git a/src/persistence/BaseMCWSPersistenceProvider.js b/src/persistence/BaseMCWSPersistenceProvider.js index 09d9ce9..9661862 100644 --- a/src/persistence/BaseMCWSPersistenceProvider.js +++ b/src/persistence/BaseMCWSPersistenceProvider.js @@ -59,15 +59,25 @@ export default class BaseMCWSPersistenceProvider { * @returns {Promise.} persistenceNamespaces */ async getPersistenceNamespaces() { - // get root namespaces, get contained namespaces. - if (!this.persistenceNamespaces) { - const rootNamespaces = await this.getRootNamespaces(); - const allContainedNamespaces = await this.getAllContainedNamespaces(rootNamespaces); + // Return cached result if available + if (this.persistenceNamespaces) { + return this.persistenceNamespaces; + } + + // If initialization is in progress, wait for it + if (!this.persistenceNamespacesPromise) { + this.persistenceNamespacesPromise = (async () => { + const rootNamespaces = await this.getRootNamespaces(); + const allContainedNamespaces = await this.getAllContainedNamespaces(rootNamespaces); + + this.persistenceNamespaces = [...rootNamespaces, ...allContainedNamespaces]; + delete this.persistenceNamespacesPromise; - this.persistenceNamespaces = [...rootNamespaces, ...allContainedNamespaces]; + return this.persistenceNamespaces; + })(); } - return this.persistenceNamespaces; + return this.persistenceNamespacesPromise; } /** diff --git a/src/services/mcws/MCWSClient.js b/src/services/mcws/MCWSClient.js index 1354389..57fa427 100644 --- a/src/services/mcws/MCWSClient.js +++ b/src/services/mcws/MCWSClient.js @@ -60,9 +60,6 @@ class MCWSClient { delete options.params; } - // Keepalive - options.keepalive = true; - try { response = await fetch(url, options); } catch (error) {