@onlineapps/conn-base-cache 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +23 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -135,10 +135,32 @@ class CacheConnector {
|
|
|
135
135
|
* await cache.connect();
|
|
136
136
|
*/
|
|
137
137
|
async connect() {
|
|
138
|
-
|
|
138
|
+
// If already connected, return success
|
|
139
|
+
if (this.connected) {
|
|
139
140
|
return true;
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
// If connection is in progress, wait for it to complete
|
|
144
|
+
if (this.connecting) {
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
const checkInterval = setInterval(() => {
|
|
147
|
+
if (this.connected) {
|
|
148
|
+
clearInterval(checkInterval);
|
|
149
|
+
resolve(true);
|
|
150
|
+
} else if (!this.connecting) {
|
|
151
|
+
clearInterval(checkInterval);
|
|
152
|
+
reject(new Error('Connection attempt failed'));
|
|
153
|
+
}
|
|
154
|
+
}, 100);
|
|
155
|
+
|
|
156
|
+
// Timeout after 5 seconds
|
|
157
|
+
setTimeout(() => {
|
|
158
|
+
clearInterval(checkInterval);
|
|
159
|
+
reject(new Error('Connection timeout'));
|
|
160
|
+
}, 5000);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
142
164
|
this.connecting = true;
|
|
143
165
|
|
|
144
166
|
try {
|