@ereo/db 0.2.36 → 0.2.38
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/dist/index.js +24 -2
- package/dist/pool.d.ts +2 -0
- package/dist/pool.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -225,6 +225,7 @@ class ConnectionPool {
|
|
|
225
225
|
totalCreated: 0,
|
|
226
226
|
totalClosed: 0
|
|
227
227
|
};
|
|
228
|
+
idleTimers = new Map;
|
|
228
229
|
constructor(config) {
|
|
229
230
|
this.config = {
|
|
230
231
|
...DEFAULT_POOL_CONFIG,
|
|
@@ -237,6 +238,11 @@ class ConnectionPool {
|
|
|
237
238
|
}
|
|
238
239
|
const idle = this.connections.pop();
|
|
239
240
|
if (idle) {
|
|
241
|
+
const timer = this.idleTimers.get(idle);
|
|
242
|
+
if (timer) {
|
|
243
|
+
clearTimeout(timer);
|
|
244
|
+
this.idleTimers.delete(idle);
|
|
245
|
+
}
|
|
240
246
|
try {
|
|
241
247
|
const isValid = await this.validateConnection(idle);
|
|
242
248
|
if (isValid) {
|
|
@@ -274,6 +280,10 @@ class ConnectionPool {
|
|
|
274
280
|
}
|
|
275
281
|
async close() {
|
|
276
282
|
this.closed = true;
|
|
283
|
+
for (const timer of this.idleTimers.values()) {
|
|
284
|
+
clearTimeout(timer);
|
|
285
|
+
}
|
|
286
|
+
this.idleTimers.clear();
|
|
277
287
|
for (const waiter of this.waitQueue) {
|
|
278
288
|
clearTimeout(waiter.timeout);
|
|
279
289
|
waiter.reject(new ConnectionError("Pool is closing"));
|
|
@@ -286,7 +296,14 @@ class ConnectionPool {
|
|
|
286
296
|
} catch {}
|
|
287
297
|
});
|
|
288
298
|
this.connections = [];
|
|
289
|
-
|
|
299
|
+
const activeClosePromises = Array.from(this.activeConnections).map(async (conn) => {
|
|
300
|
+
try {
|
|
301
|
+
await this.closeConnection(conn);
|
|
302
|
+
this.stats.totalClosed++;
|
|
303
|
+
} catch {}
|
|
304
|
+
});
|
|
305
|
+
this.activeConnections.clear();
|
|
306
|
+
await Promise.all([...closePromises, ...activeClosePromises]);
|
|
290
307
|
}
|
|
291
308
|
getStats() {
|
|
292
309
|
return {
|
|
@@ -350,7 +367,11 @@ class ConnectionPool {
|
|
|
350
367
|
scheduleIdleTimeout(connection) {
|
|
351
368
|
if (this.config.idleTimeoutMs <= 0)
|
|
352
369
|
return;
|
|
353
|
-
|
|
370
|
+
const existing = this.idleTimers.get(connection);
|
|
371
|
+
if (existing)
|
|
372
|
+
clearTimeout(existing);
|
|
373
|
+
const timer = setTimeout(async () => {
|
|
374
|
+
this.idleTimers.delete(connection);
|
|
354
375
|
const index = this.connections.indexOf(connection);
|
|
355
376
|
if (index !== -1) {
|
|
356
377
|
this.connections.splice(index, 1);
|
|
@@ -360,6 +381,7 @@ class ConnectionPool {
|
|
|
360
381
|
} catch {}
|
|
361
382
|
}
|
|
362
383
|
}, this.config.idleTimeoutMs);
|
|
384
|
+
this.idleTimers.set(connection, timer);
|
|
363
385
|
}
|
|
364
386
|
delay(ms) {
|
|
365
387
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
package/dist/pool.d.ts
CHANGED
|
@@ -56,6 +56,8 @@ export declare abstract class ConnectionPool<T> {
|
|
|
56
56
|
totalCreated: number;
|
|
57
57
|
totalClosed: number;
|
|
58
58
|
};
|
|
59
|
+
/** Track idle timeout timers so they can be cleaned up */
|
|
60
|
+
private idleTimers;
|
|
59
61
|
constructor(config?: PoolConfig);
|
|
60
62
|
/**
|
|
61
63
|
* Create a new connection.
|
package/dist/pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAO7D;;GAEG;AACH,eAAO,MAAM,mBAAmB,EA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G,OAAO,CA6B5D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ereo/db",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.38",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Enoch Kujem Abassey",
|
|
6
6
|
"homepage": "https://ereojs.github.io/ereoJS",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"typecheck": "tsc --noEmit"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@ereo/core": "
|
|
36
|
+
"@ereo/core": "workspace:*"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/bun": "^1.1.0",
|