Skip to content

Commit 7c48b1a

Browse files
committed
better practice
1 parent c25c6b5 commit 7c48b1a

File tree

1 file changed

+10
-1
lines changed
  • services/static-webserver/client/source/class/osparc/store

1 file changed

+10
-1
lines changed

services/static-webserver/client/source/class/osparc/store/Services.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ qx.Class.define("osparc.store.Services", {
106106
return this.__servicesPromisesCached[key][version];
107107
}
108108

109-
return new Promise((resolve, reject) => {
109+
// Create a new promise
110+
const promise = new Promise((resolve, reject) => {
110111
if (
111112
useCache &&
112113
this.__isInCache(key, version) &&
@@ -145,6 +146,14 @@ qx.Class.define("osparc.store.Services", {
145146
delete this.__servicesPromisesCached[key][version];
146147
});
147148
});
149+
150+
// Store the promise in the cache
151+
// The point of keeping this assignment outside of the main Promise block is to
152+
// ensure that the promise is immediately stored in the cache before any asynchronous
153+
// operations (like fetch) are executed. This prevents duplicate requests for the
154+
// same key and version when multiple consumers call getService concurrently.
155+
this.__servicesPromisesCached[key][version] = promise;
156+
return promise;
148157
},
149158

150159
getStudyServices: function(studyId) {

0 commit comments

Comments
 (0)