lightning-pool 4.11.0 → 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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![NPM Version][npm-image]][npm-url]
4
4
  [![NPM Downloads][downloads-image]][downloads-url]
5
- [![CircleCI][circleci-image]][circleci-url]
5
+ [![CI Tests][ci-test-image]][ci-test-url]
6
6
  [![Test Coverage][coveralls-image]][coveralls-url]
7
7
 
8
8
  ## About
@@ -377,8 +377,8 @@ Pool.PoolState (Number):
377
377
 
378
378
  [npm-image]: https://img.shields.io/npm/v/lightning-pool.svg
379
379
  [npm-url]: https://npmjs.org/package/lightning-pool
380
- [circleci-image]: https://circleci.com/gh/panates/lightning-pool/tree/master.svg?style=shield
381
- [circleci-url]: https://circleci.com/gh/panates/lightning-pool/tree/master
380
+ [ci-test-image]: https://github.com/panates/lightning-pool/actions/workflows/test.yml/badge.svg
381
+ [ci-test-url]: https://github.com/panates/lightning-pool/actions/workflows/test.yml
382
382
  [coveralls-image]: https://img.shields.io/coveralls/panates/lightning-pool/master.svg
383
383
  [coveralls-url]: https://coveralls.io/r/panates/lightning-pool
384
384
  [downloads-image]: https://img.shields.io/npm/dm/lightning-pool.svg
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 house keeping and any other internal logic.
94
- * Note: This method is not need to be called. Pool instance will automatically be started when acquire() method is called
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 >= constants_js_1.PoolState.CLOSING) {
100
- throw new Error('Closed pool can not be started again');
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.8.3"}
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 house keeping and any other internal logic.
90
- * Note: This method is not need to be called. Pool instance will automatically be started when acquire() method is called
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 >= PoolState.CLOSING) {
96
- throw new Error('Closed pool can not be started again');
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.8.3"}
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lightning-pool",
3
3
  "description": "Fastest generic Pool written with TypeScript",
4
- "version": "4.11.0",
4
+ "version": "4.12.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
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 house keeping and any other internal logic.
49
- * Note: This method is not need to be called. Pool instance will automatically be started when acquire() method is called
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
  /**