lightning-pool 4.11.1 → 4.12.0
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/cjs/pool.js +17 -6
- package/cjs/tsconfig-build-cjs.tsbuildinfo +1 -1
- package/esm/pool.js +17 -6
- package/esm/tsconfig-build-esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/types/pool.d.ts +3 -3
package/cjs/pool.js
CHANGED
|
@@ -13,8 +13,8 @@ const resource_item_js_1 = require("./resource-item.js");
|
|
|
13
13
|
class Pool extends events_1.EventEmitter {
|
|
14
14
|
constructor(factory, config) {
|
|
15
15
|
super();
|
|
16
|
-
this._requestQueue = new doublylinked_1.default();
|
|
17
16
|
this._allResources = new Map();
|
|
17
|
+
this._requestQueue = new doublylinked_1.default();
|
|
18
18
|
this._acquiredResources = new doublylinked_1.default();
|
|
19
19
|
this._idleResources = new doublylinked_1.default();
|
|
20
20
|
this._creating = 0;
|
|
@@ -90,15 +90,25 @@ class Pool extends events_1.EventEmitter {
|
|
|
90
90
|
return this._state;
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
|
-
* Starts the pool and begins creating of resources, starts
|
|
94
|
-
* Note: This method is not
|
|
93
|
+
* Starts the pool and begins creating of resources, starts the housekeeper and any other internal logic.
|
|
94
|
+
* Note: This method is not needed to be called. Pool instance will automatically be started when acquire() method is called
|
|
95
95
|
*/
|
|
96
96
|
start() {
|
|
97
97
|
if (this._state === constants_js_1.PoolState.STARTED)
|
|
98
98
|
return;
|
|
99
|
-
if (this._state
|
|
100
|
-
throw new Error('
|
|
101
|
-
}
|
|
99
|
+
if (this._state === constants_js_1.PoolState.CLOSING) {
|
|
100
|
+
throw new Error(`Can't start the pool while it is closing`);
|
|
101
|
+
}
|
|
102
|
+
if (this._allResources.size)
|
|
103
|
+
this._allResources = new Map();
|
|
104
|
+
if (this._requestQueue.length)
|
|
105
|
+
this._requestQueue = new doublylinked_1.default();
|
|
106
|
+
if (this._acquiredResources.length)
|
|
107
|
+
this._acquiredResources = new doublylinked_1.default();
|
|
108
|
+
if (this._idleResources.length)
|
|
109
|
+
this._idleResources = new doublylinked_1.default();
|
|
110
|
+
this._creating = 0;
|
|
111
|
+
this._requestsProcessing = 0;
|
|
102
112
|
this._state = constants_js_1.PoolState.STARTED;
|
|
103
113
|
this._setHouseKeep(this.options.houseKeepInterval);
|
|
104
114
|
this._ensureMin();
|
|
@@ -143,6 +153,7 @@ class Pool extends events_1.EventEmitter {
|
|
|
143
153
|
}
|
|
144
154
|
if (Date.now() > startTime + terminateWait) {
|
|
145
155
|
clearInterval(this._closeWaitTimer);
|
|
156
|
+
this._allResources.clear();
|
|
146
157
|
this._closeWaitTimer = undefined;
|
|
147
158
|
this._acquiredResources.forEach(t => this.release(t.resource));
|
|
148
159
|
this.emit('terminate');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/abort-error.ts","../../src/constants.ts","../../src/index.ts","../../src/pool-options.ts","../../src/pool-request.ts","../../src/pool.ts","../../src/resource-item.ts","../../src/types.ts"],"version":"5.
|
|
1
|
+
{"root":["../../src/abort-error.ts","../../src/constants.ts","../../src/index.ts","../../src/pool-options.ts","../../src/pool-request.ts","../../src/pool.ts","../../src/resource-item.ts","../../src/types.ts"],"version":"5.9.3"}
|
package/esm/pool.js
CHANGED
|
@@ -9,8 +9,8 @@ import { ResourceItem } from './resource-item.js';
|
|
|
9
9
|
export class Pool extends EventEmitter {
|
|
10
10
|
constructor(factory, config) {
|
|
11
11
|
super();
|
|
12
|
-
this._requestQueue = new DoublyLinked();
|
|
13
12
|
this._allResources = new Map();
|
|
13
|
+
this._requestQueue = new DoublyLinked();
|
|
14
14
|
this._acquiredResources = new DoublyLinked();
|
|
15
15
|
this._idleResources = new DoublyLinked();
|
|
16
16
|
this._creating = 0;
|
|
@@ -86,15 +86,25 @@ export class Pool extends EventEmitter {
|
|
|
86
86
|
return this._state;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
|
-
* Starts the pool and begins creating of resources, starts
|
|
90
|
-
* Note: This method is not
|
|
89
|
+
* Starts the pool and begins creating of resources, starts the housekeeper and any other internal logic.
|
|
90
|
+
* Note: This method is not needed to be called. Pool instance will automatically be started when acquire() method is called
|
|
91
91
|
*/
|
|
92
92
|
start() {
|
|
93
93
|
if (this._state === PoolState.STARTED)
|
|
94
94
|
return;
|
|
95
|
-
if (this._state
|
|
96
|
-
throw new Error('
|
|
97
|
-
}
|
|
95
|
+
if (this._state === PoolState.CLOSING) {
|
|
96
|
+
throw new Error(`Can't start the pool while it is closing`);
|
|
97
|
+
}
|
|
98
|
+
if (this._allResources.size)
|
|
99
|
+
this._allResources = new Map();
|
|
100
|
+
if (this._requestQueue.length)
|
|
101
|
+
this._requestQueue = new DoublyLinked();
|
|
102
|
+
if (this._acquiredResources.length)
|
|
103
|
+
this._acquiredResources = new DoublyLinked();
|
|
104
|
+
if (this._idleResources.length)
|
|
105
|
+
this._idleResources = new DoublyLinked();
|
|
106
|
+
this._creating = 0;
|
|
107
|
+
this._requestsProcessing = 0;
|
|
98
108
|
this._state = PoolState.STARTED;
|
|
99
109
|
this._setHouseKeep(this.options.houseKeepInterval);
|
|
100
110
|
this._ensureMin();
|
|
@@ -139,6 +149,7 @@ export class Pool extends EventEmitter {
|
|
|
139
149
|
}
|
|
140
150
|
if (Date.now() > startTime + terminateWait) {
|
|
141
151
|
clearInterval(this._closeWaitTimer);
|
|
152
|
+
this._allResources.clear();
|
|
142
153
|
this._closeWaitTimer = undefined;
|
|
143
154
|
this._acquiredResources.forEach(t => this.release(t.resource));
|
|
144
155
|
this.emit('terminate');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/abort-error.ts","../../src/constants.ts","../../src/index.ts","../../src/pool-options.ts","../../src/pool-request.ts","../../src/pool.ts","../../src/resource-item.ts","../../src/types.ts"],"version":"5.
|
|
1
|
+
{"root":["../../src/abort-error.ts","../../src/constants.ts","../../src/index.ts","../../src/pool-options.ts","../../src/pool-request.ts","../../src/pool.ts","../../src/resource-item.ts","../../src/types.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
package/types/pool.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { Callback, PoolConfiguration, PoolFactory } from './types.js';
|
|
|
5
5
|
export declare class Pool<T = any> extends EventEmitter {
|
|
6
6
|
private readonly _options;
|
|
7
7
|
private readonly _factory;
|
|
8
|
-
private _requestQueue;
|
|
9
8
|
private _allResources;
|
|
9
|
+
private _requestQueue;
|
|
10
10
|
private _acquiredResources;
|
|
11
11
|
private _idleResources;
|
|
12
12
|
private _creating;
|
|
@@ -45,8 +45,8 @@ export declare class Pool<T = any> extends EventEmitter {
|
|
|
45
45
|
*/
|
|
46
46
|
get state(): PoolState;
|
|
47
47
|
/**
|
|
48
|
-
* Starts the pool and begins creating of resources, starts
|
|
49
|
-
* Note: This method is not
|
|
48
|
+
* Starts the pool and begins creating of resources, starts the housekeeper and any other internal logic.
|
|
49
|
+
* Note: This method is not needed to be called. Pool instance will automatically be started when acquire() method is called
|
|
50
50
|
*/
|
|
51
51
|
start(): void;
|
|
52
52
|
/**
|