lightning-pool 4.14.0 → 4.14.3
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 +12 -18
- package/abort-error.d.ts +11 -0
- package/abort-error.js +11 -0
- package/constants.d.ts +12 -0
- package/constants.js +12 -0
- package/index.d.ts +8 -0
- package/index.js +8 -0
- package/package.json +9 -3
- package/pool-options.d.ts +72 -0
- package/pool-options.js +72 -0
- package/pool-request.d.ts +15 -0
- package/pool-request.js +17 -0
- package/pool.d.ts +125 -10
- package/pool.js +107 -8
- package/resource-item.d.ts +10 -0
- package/resource-item.js +10 -0
- package/types.d.ts +124 -0
- package/CHANGELOG.md +0 -451
package/README.md
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
# lightning-pool
|
|
2
2
|
|
|
3
|
+
High performance resource pool written with TypeScript.
|
|
4
|
+
|
|
3
5
|
[![NPM Version][npm-image]][npm-url]
|
|
4
6
|
[![NPM Downloads][downloads-image]][downloads-url]
|
|
5
7
|
[![CI Tests][ci-test-image]][ci-test-url]
|
|
6
8
|
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Documentation: [API reference](docs/API.md) · [Benchmarks](docs/BENCHMARKS.md)
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
## Features
|
|
11
13
|
|
|
12
|
-
- A fast Resource Pool implementation for JavaScript - see [
|
|
14
|
+
- A fast Resource Pool implementation for JavaScript - see [docs/BENCHMARKS.md](docs/BENCHMARKS.md) for the numbers against [generic-pool](https://github.com/coopernurse/node-pool), or [benchmark/README.md](benchmark/README.md) to reproduce them yourself
|
|
13
15
|
- Advanced configuration options, suits for enterprise level applications
|
|
14
16
|
- Configuration can be changed while pool running
|
|
15
17
|
- Promise based factory supported
|
|
16
18
|
- Supports validation and resource reset
|
|
17
|
-
- Fully tested
|
|
19
|
+
- Fully tested (see the coverage badge above)
|
|
18
20
|
|
|
19
21
|
## Installation
|
|
20
22
|
|
|
@@ -78,29 +80,21 @@ await pool.close(5000);
|
|
|
78
80
|
|
|
79
81
|
## Documentation
|
|
80
82
|
|
|
81
|
-
See [
|
|
83
|
+
See [docs/API.md](docs/API.md) for the full API reference - factory/options shape, every method and property,
|
|
82
84
|
emitted events, and the `PoolState`/`ResourceState` enums.
|
|
83
85
|
|
|
84
86
|
## Node Compatibility
|
|
85
87
|
|
|
86
|
-
- node `>=
|
|
88
|
+
- node `>= 22.0`;
|
|
87
89
|
|
|
88
90
|
### License
|
|
89
91
|
[MIT](LICENSE)
|
|
90
92
|
|
|
91
|
-
[npm-image]: https://img.shields.io/npm/v/lightning-pool
|
|
93
|
+
[npm-image]: https://img.shields.io/npm/v/lightning-pool
|
|
92
94
|
[npm-url]: https://npmjs.org/package/lightning-pool
|
|
95
|
+
[downloads-image]: https://img.shields.io/npm/dm/lightning-pool.svg
|
|
96
|
+
[downloads-url]: https://npmjs.org/package/lightning-pool
|
|
93
97
|
[ci-test-image]: https://github.com/panates/lightning-pool/actions/workflows/test.yml/badge.svg
|
|
94
98
|
[ci-test-url]: https://github.com/panates/lightning-pool/actions/workflows/test.yml
|
|
95
|
-
[coveralls-image]: https://img.shields.io/coveralls/panates/lightning-pool/
|
|
99
|
+
[coveralls-image]: https://img.shields.io/coveralls/panates/lightning-pool/main.svg
|
|
96
100
|
[coveralls-url]: https://coveralls.io/r/panates/lightning-pool
|
|
97
|
-
[downloads-image]: https://img.shields.io/npm/dm/lightning-pool.svg
|
|
98
|
-
[downloads-url]: https://npmjs.org/package/lightning-pool
|
|
99
|
-
[gitter-image]: https://badges.gitter.im/panates/lightning-pool.svg
|
|
100
|
-
[gitter-url]: https://gitter.im/panates/lightning-pool?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
101
|
-
[dependencies-image]: https://david-dm.org/panates/lightning-pool/status.svg
|
|
102
|
-
[dependencies-url]:https://david-dm.org/panates/lightning-pool
|
|
103
|
-
[devdependencies-image]: https://david-dm.org/panates/lightning-pool/dev-status.svg
|
|
104
|
-
[devdependencies-url]:https://david-dm.org/panates/lightning-pool?type=dev
|
|
105
|
-
[quality-image]: http://npm.packagequality.com/shield/lightning-pool.png
|
|
106
|
-
[quality-url]: http://packagequality.com/#?package=lightning-pool
|
package/abort-error.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throw (or reject with) this from `PoolFactory.create()` to abort resource
|
|
3
|
+
* creation immediately instead of retrying.
|
|
4
|
+
*
|
|
5
|
+
* @remarks Normally, when `create()` fails, the `Pool` retries up to
|
|
6
|
+
* `PoolConfiguration.acquireMaxRetries` times (waiting `acquireRetryWait`
|
|
7
|
+
* between attempts) before failing the pending `acquire()`. An `AbortError`
|
|
8
|
+
* skips that retry loop entirely and fails the `acquire()` right away -
|
|
9
|
+
* useful for errors that retrying can never fix (e.g. invalid
|
|
10
|
+
* credentials), as opposed to transient ones (e.g. a connection timeout).
|
|
11
|
+
*/
|
|
1
12
|
export declare class AbortError extends Error {
|
|
2
13
|
}
|
package/abort-error.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throw (or reject with) this from `PoolFactory.create()` to abort resource
|
|
3
|
+
* creation immediately instead of retrying.
|
|
4
|
+
*
|
|
5
|
+
* @remarks Normally, when `create()` fails, the `Pool` retries up to
|
|
6
|
+
* `PoolConfiguration.acquireMaxRetries` times (waiting `acquireRetryWait`
|
|
7
|
+
* between attempts) before failing the pending `acquire()`. An `AbortError`
|
|
8
|
+
* skips that retry loop entirely and fails the `acquire()` right away -
|
|
9
|
+
* useful for errors that retrying can never fix (e.g. invalid
|
|
10
|
+
* credentials), as opposed to transient ones (e.g. a connection timeout).
|
|
11
|
+
*/
|
|
1
12
|
export class AbortError extends Error {
|
|
2
13
|
}
|
package/constants.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
/** Lifecycle state of a `Pool`, exposed as `pool.state`. */
|
|
1
2
|
export declare enum PoolState {
|
|
3
|
+
/** The `Pool` has not been started yet. */
|
|
2
4
|
IDLE = 0,
|
|
5
|
+
/** The `Pool` is running. */
|
|
3
6
|
STARTED = 1,
|
|
7
|
+
/** Shutdown is in progress (`close()`/`closeAsync()` was called). */
|
|
4
8
|
CLOSING = 2,
|
|
9
|
+
/** The `Pool` has fully shut down. Calling `start()` again brings it back to `STARTED`. */
|
|
5
10
|
CLOSED = 3
|
|
6
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* State of an individual pooled resource. Internal bookkeeping, but exposed
|
|
14
|
+
* (mostly useful when inspecting events or writing tests).
|
|
15
|
+
*/
|
|
7
16
|
export declare enum ResourceState {
|
|
17
|
+
/** The resource is idle and available for `acquire()`. */
|
|
8
18
|
IDLE = 0,
|
|
19
|
+
/** The resource is currently acquired by a caller. */
|
|
9
20
|
ACQUIRED = 1,
|
|
21
|
+
/** The resource is being validated (see `PoolConfiguration.validation`) before being handed out. */
|
|
10
22
|
VALIDATION = 2
|
|
11
23
|
}
|
package/constants.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
+
/** Lifecycle state of a `Pool`, exposed as `pool.state`. */
|
|
1
2
|
export var PoolState;
|
|
2
3
|
(function (PoolState) {
|
|
4
|
+
/** The `Pool` has not been started yet. */
|
|
3
5
|
PoolState[PoolState["IDLE"] = 0] = "IDLE";
|
|
6
|
+
/** The `Pool` is running. */
|
|
4
7
|
PoolState[PoolState["STARTED"] = 1] = "STARTED";
|
|
8
|
+
/** Shutdown is in progress (`close()`/`closeAsync()` was called). */
|
|
5
9
|
PoolState[PoolState["CLOSING"] = 2] = "CLOSING";
|
|
10
|
+
/** The `Pool` has fully shut down. Calling `start()` again brings it back to `STARTED`. */
|
|
6
11
|
PoolState[PoolState["CLOSED"] = 3] = "CLOSED";
|
|
7
12
|
})(PoolState || (PoolState = {}));
|
|
13
|
+
/**
|
|
14
|
+
* State of an individual pooled resource. Internal bookkeeping, but exposed
|
|
15
|
+
* (mostly useful when inspecting events or writing tests).
|
|
16
|
+
*/
|
|
8
17
|
export var ResourceState;
|
|
9
18
|
(function (ResourceState) {
|
|
19
|
+
/** The resource is idle and available for `acquire()`. */
|
|
10
20
|
ResourceState[ResourceState["IDLE"] = 0] = "IDLE";
|
|
21
|
+
/** The resource is currently acquired by a caller. */
|
|
11
22
|
ResourceState[ResourceState["ACQUIRED"] = 1] = "ACQUIRED";
|
|
23
|
+
/** The resource is being validated (see `PoolConfiguration.validation`) before being handed out. */
|
|
12
24
|
ResourceState[ResourceState["VALIDATION"] = 2] = "VALIDATION";
|
|
13
25
|
})(ResourceState || (ResourceState = {}));
|
package/index.d.ts
CHANGED
|
@@ -4,4 +4,12 @@ export * from './abort-error.js';
|
|
|
4
4
|
export * from './constants.js';
|
|
5
5
|
export * from './pool.js';
|
|
6
6
|
export * from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new `Pool`. Equivalent to `new Pool(factory, config)` - a
|
|
9
|
+
* convenience so callers don't need to import the `Pool` class directly.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T - The resource type this pool manages.
|
|
12
|
+
* @param factory - Creates, destroys, and (optionally) resets/validates resources.
|
|
13
|
+
* @param config - Initial options; every option can also be changed later via `pool.options`.
|
|
14
|
+
*/
|
|
7
15
|
export declare function createPool<T = any>(factory: PoolFactory<T>, config?: PoolConfiguration): Pool<T>;
|
package/index.js
CHANGED
|
@@ -3,6 +3,14 @@ export * from './abort-error.js';
|
|
|
3
3
|
export * from './constants.js';
|
|
4
4
|
export * from './pool.js';
|
|
5
5
|
export * from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new `Pool`. Equivalent to `new Pool(factory, config)` - a
|
|
8
|
+
* convenience so callers don't need to import the `Pool` class directly.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - The resource type this pool manages.
|
|
11
|
+
* @param factory - Creates, destroys, and (optionally) resets/validates resources.
|
|
12
|
+
* @param config - Initial options; every option can also be changed later via `pool.options`.
|
|
13
|
+
*/
|
|
6
14
|
export function createPool(factory, config) {
|
|
7
15
|
return new Pool(factory, config);
|
|
8
16
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightning-pool",
|
|
3
3
|
"description": "Fastest generic Pool written with TypeScript",
|
|
4
|
-
"version": "4.14.
|
|
4
|
+
"version": "4.14.3",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"doublylinked": "^2.5.6",
|
|
9
9
|
"putil-promisify": "^1.10.1",
|
|
10
|
-
"tslib": "^2.
|
|
10
|
+
"tslib": "^2.9.1"
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
13
13
|
"module": "./index.js",
|
|
@@ -19,12 +19,18 @@
|
|
|
19
19
|
},
|
|
20
20
|
"./package.json": "./package.json"
|
|
21
21
|
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22"
|
|
24
|
+
},
|
|
22
25
|
"repository": {
|
|
23
26
|
"type": "git",
|
|
24
27
|
"url": "git+https://github.com/panates/lightning-pool.git"
|
|
25
28
|
},
|
|
26
29
|
"contributors": [
|
|
27
|
-
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
30
|
+
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
31
|
+
"Ilker Gurelli <i.gurelli@panates.com>",
|
|
32
|
+
"Onur Tokel <o.tokel@panates.com>",
|
|
33
|
+
"Bircan Yuruk <b.yuruk@panates.com>"
|
|
28
34
|
],
|
|
29
35
|
"keywords": [
|
|
30
36
|
"pool",
|
package/pool-options.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import type { Pool } from './pool.js';
|
|
3
3
|
import type { PoolConfiguration } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Live, mutable configuration for a `Pool`, exposed as `pool.options`. Every
|
|
6
|
+
* property is a get/set pair - assigning one takes effect immediately (e.g.
|
|
7
|
+
* `pool.options.max = 20`) and emits a `'change'` event that `Pool` reacts
|
|
8
|
+
* to (adjusting the housekeeper interval, topping up `min`/`minIdle`, etc.).
|
|
9
|
+
* See `PoolConfiguration` for what each option means; the defaults are the
|
|
10
|
+
* same for both.
|
|
11
|
+
*/
|
|
4
12
|
export declare class PoolOptions extends EventEmitter {
|
|
5
13
|
readonly pool: Pool;
|
|
6
14
|
private _acquireMaxRetries;
|
|
@@ -15,27 +23,91 @@ export declare class PoolOptions extends EventEmitter {
|
|
|
15
23
|
private _maxQueue;
|
|
16
24
|
private _validation;
|
|
17
25
|
constructor(pool: Pool);
|
|
26
|
+
/** @defaultValue `0` - fail on the first error, no retries. */
|
|
18
27
|
get acquireMaxRetries(): number;
|
|
28
|
+
/** Negative values reset to the default instead of being applied. */
|
|
19
29
|
set acquireMaxRetries(val: number);
|
|
30
|
+
/** @defaultValue `2000` (milliseconds) */
|
|
20
31
|
get acquireRetryWait(): number;
|
|
32
|
+
/** Negative values reset to the default instead of being applied. */
|
|
21
33
|
set acquireRetryWait(val: number);
|
|
34
|
+
/** @defaultValue `0` (milliseconds) - no timeout. */
|
|
22
35
|
get acquireTimeoutMillis(): number;
|
|
36
|
+
/** Negative values reset to the default instead of being applied. */
|
|
23
37
|
set acquireTimeoutMillis(val: number);
|
|
38
|
+
/**
|
|
39
|
+
* If `true`, idle resources are handed out first-in-first-out; if
|
|
40
|
+
* `false`, last-in-first-out.
|
|
41
|
+
*
|
|
42
|
+
* @defaultValue `true`
|
|
43
|
+
*/
|
|
24
44
|
get fifo(): boolean;
|
|
25
45
|
set fifo(val: boolean);
|
|
46
|
+
/** @defaultValue `30000` (milliseconds) */
|
|
26
47
|
get idleTimeoutMillis(): number;
|
|
48
|
+
/** Negative values reset to the default instead of being applied. */
|
|
27
49
|
set idleTimeoutMillis(val: number);
|
|
50
|
+
/** @defaultValue `1000` (milliseconds) */
|
|
28
51
|
get houseKeepInterval(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Negative values reset to the default instead of being applied.
|
|
54
|
+
*
|
|
55
|
+
* @remarks Setting this restarts the housekeeper timer on the running
|
|
56
|
+
* `Pool` with the new interval.
|
|
57
|
+
*/
|
|
29
58
|
set houseKeepInterval(val: number);
|
|
59
|
+
/** @defaultValue `0` */
|
|
30
60
|
get min(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Negative values reset to the default instead of being applied.
|
|
63
|
+
*
|
|
64
|
+
* @remarks Raising this above the current `max` also raises `max` to
|
|
65
|
+
* match, since `min` can never exceed `max`. On a running `Pool`, raising
|
|
66
|
+
* `min` triggers creating resources to satisfy the new minimum.
|
|
67
|
+
*/
|
|
31
68
|
set min(val: number);
|
|
69
|
+
/** @defaultValue `0` */
|
|
32
70
|
get minIdle(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Negative values reset to the default instead of being applied.
|
|
73
|
+
*
|
|
74
|
+
* @remarks On a running `Pool`, raising this triggers creating resources
|
|
75
|
+
* to satisfy the new minimum idle count.
|
|
76
|
+
*/
|
|
33
77
|
set minIdle(val: number);
|
|
78
|
+
/** @defaultValue `10` */
|
|
34
79
|
get max(): number;
|
|
80
|
+
/**
|
|
81
|
+
* Negative values reset to the default instead of being applied; `0` or
|
|
82
|
+
* below the current `min` is clamped up to at least `1`/`min`.
|
|
83
|
+
*
|
|
84
|
+
* @remarks Lowering this below the current `min` also lowers `min` to
|
|
85
|
+
* match, since `min` can never exceed `max`.
|
|
86
|
+
*/
|
|
35
87
|
set max(val: number);
|
|
88
|
+
/** @defaultValue `1000` */
|
|
36
89
|
get maxQueue(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Negative values reset to the default instead of being applied;
|
|
92
|
+
* otherwise clamped up to at least `1`.
|
|
93
|
+
*/
|
|
37
94
|
set maxQueue(val: number);
|
|
95
|
+
/**
|
|
96
|
+
* If `true`, a resource is validated via `factory.validate()` before
|
|
97
|
+
* being handed out (when the factory provides one).
|
|
98
|
+
*
|
|
99
|
+
* @defaultValue `true`
|
|
100
|
+
*/
|
|
38
101
|
get validation(): boolean;
|
|
39
102
|
set validation(val: boolean);
|
|
103
|
+
/**
|
|
104
|
+
* Copies every recognized option from `values` onto this instance,
|
|
105
|
+
* emitting a `'change'` event per option (same as assigning each
|
|
106
|
+
* individually). Unknown keys are silently ignored.
|
|
107
|
+
*
|
|
108
|
+
* @param values - A plain `PoolConfiguration` object, or another
|
|
109
|
+
* `PoolOptions` instance to copy settings from (e.g. to clone one pool's
|
|
110
|
+
* configuration onto another).
|
|
111
|
+
*/
|
|
40
112
|
assign(values: PoolConfiguration | PoolOptions): void;
|
|
41
113
|
}
|
package/pool-options.js
CHANGED
|
@@ -12,6 +12,14 @@ const defaultValues = {
|
|
|
12
12
|
maxQueue: 1000,
|
|
13
13
|
validation: true,
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Live, mutable configuration for a `Pool`, exposed as `pool.options`. Every
|
|
17
|
+
* property is a get/set pair - assigning one takes effect immediately (e.g.
|
|
18
|
+
* `pool.options.max = 20`) and emits a `'change'` event that `Pool` reacts
|
|
19
|
+
* to (adjusting the housekeeper interval, topping up `min`/`minIdle`, etc.).
|
|
20
|
+
* See `PoolConfiguration` for what each option means; the defaults are the
|
|
21
|
+
* same for both.
|
|
22
|
+
*/
|
|
15
23
|
export class PoolOptions extends EventEmitter {
|
|
16
24
|
pool;
|
|
17
25
|
_acquireMaxRetries = defaultValues.acquireMaxRetries;
|
|
@@ -30,28 +38,40 @@ export class PoolOptions extends EventEmitter {
|
|
|
30
38
|
this.pool = pool;
|
|
31
39
|
this.pool = pool;
|
|
32
40
|
}
|
|
41
|
+
/** @defaultValue `0` - fail on the first error, no retries. */
|
|
33
42
|
get acquireMaxRetries() {
|
|
34
43
|
return this._acquireMaxRetries;
|
|
35
44
|
}
|
|
45
|
+
/** Negative values reset to the default instead of being applied. */
|
|
36
46
|
set acquireMaxRetries(val) {
|
|
37
47
|
this._acquireMaxRetries = val >= 0 ? val : defaultValues.acquireMaxRetries;
|
|
38
48
|
this.emit('change', 'acquireMaxRetries', this._acquireMaxRetries);
|
|
39
49
|
}
|
|
50
|
+
/** @defaultValue `2000` (milliseconds) */
|
|
40
51
|
get acquireRetryWait() {
|
|
41
52
|
return this._acquireRetryWait;
|
|
42
53
|
}
|
|
54
|
+
/** Negative values reset to the default instead of being applied. */
|
|
43
55
|
set acquireRetryWait(val) {
|
|
44
56
|
this._acquireRetryWait = val >= 0 ? val : defaultValues.acquireRetryWait;
|
|
45
57
|
this.emit('change', 'acquireRetryWait', this._acquireRetryWait);
|
|
46
58
|
}
|
|
59
|
+
/** @defaultValue `0` (milliseconds) - no timeout. */
|
|
47
60
|
get acquireTimeoutMillis() {
|
|
48
61
|
return this._acquireTimeoutMillis;
|
|
49
62
|
}
|
|
63
|
+
/** Negative values reset to the default instead of being applied. */
|
|
50
64
|
set acquireTimeoutMillis(val) {
|
|
51
65
|
this._acquireTimeoutMillis =
|
|
52
66
|
val >= 0 ? val : defaultValues.acquireTimeoutMillis;
|
|
53
67
|
this.emit('change', 'acquireTimeoutMillis', this._acquireTimeoutMillis);
|
|
54
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* If `true`, idle resources are handed out first-in-first-out; if
|
|
71
|
+
* `false`, last-in-first-out.
|
|
72
|
+
*
|
|
73
|
+
* @defaultValue `true`
|
|
74
|
+
*/
|
|
55
75
|
get fifo() {
|
|
56
76
|
return this._fifo;
|
|
57
77
|
}
|
|
@@ -60,52 +80,95 @@ export class PoolOptions extends EventEmitter {
|
|
|
60
80
|
this._fifo = !!val;
|
|
61
81
|
this.emit('change', 'fifo', this.fifo);
|
|
62
82
|
}
|
|
83
|
+
/** @defaultValue `30000` (milliseconds) */
|
|
63
84
|
get idleTimeoutMillis() {
|
|
64
85
|
return this._idleTimeoutMillis;
|
|
65
86
|
}
|
|
87
|
+
/** Negative values reset to the default instead of being applied. */
|
|
66
88
|
set idleTimeoutMillis(val) {
|
|
67
89
|
this._idleTimeoutMillis = val >= 0 ? val : defaultValues.idleTimeoutMillis;
|
|
68
90
|
this.emit('change', 'idleTimeoutMillis', this._idleTimeoutMillis);
|
|
69
91
|
}
|
|
92
|
+
/** @defaultValue `1000` (milliseconds) */
|
|
70
93
|
get houseKeepInterval() {
|
|
71
94
|
return this._houseKeepInterval;
|
|
72
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Negative values reset to the default instead of being applied.
|
|
98
|
+
*
|
|
99
|
+
* @remarks Setting this restarts the housekeeper timer on the running
|
|
100
|
+
* `Pool` with the new interval.
|
|
101
|
+
*/
|
|
73
102
|
set houseKeepInterval(val) {
|
|
74
103
|
this._houseKeepInterval = val >= 0 ? val : defaultValues.houseKeepInterval;
|
|
75
104
|
this.emit('change', 'houseKeepInterval', this._houseKeepInterval);
|
|
76
105
|
}
|
|
106
|
+
/** @defaultValue `0` */
|
|
77
107
|
get min() {
|
|
78
108
|
return this._min;
|
|
79
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Negative values reset to the default instead of being applied.
|
|
112
|
+
*
|
|
113
|
+
* @remarks Raising this above the current `max` also raises `max` to
|
|
114
|
+
* match, since `min` can never exceed `max`. On a running `Pool`, raising
|
|
115
|
+
* `min` triggers creating resources to satisfy the new minimum.
|
|
116
|
+
*/
|
|
80
117
|
set min(val) {
|
|
81
118
|
this._min = val >= 0 ? val : defaultValues.min;
|
|
82
119
|
if (this._min > this._max)
|
|
83
120
|
this._max = this._min;
|
|
84
121
|
this.emit('change', 'min', this._min);
|
|
85
122
|
}
|
|
123
|
+
/** @defaultValue `0` */
|
|
86
124
|
get minIdle() {
|
|
87
125
|
return this._minIdle;
|
|
88
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Negative values reset to the default instead of being applied.
|
|
129
|
+
*
|
|
130
|
+
* @remarks On a running `Pool`, raising this triggers creating resources
|
|
131
|
+
* to satisfy the new minimum idle count.
|
|
132
|
+
*/
|
|
89
133
|
set minIdle(val) {
|
|
90
134
|
this._minIdle = val >= 0 ? val : defaultValues.minIdle;
|
|
91
135
|
this.emit('change', 'minIdle', this.minIdle);
|
|
92
136
|
}
|
|
137
|
+
/** @defaultValue `10` */
|
|
93
138
|
get max() {
|
|
94
139
|
return this._max;
|
|
95
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Negative values reset to the default instead of being applied; `0` or
|
|
143
|
+
* below the current `min` is clamped up to at least `1`/`min`.
|
|
144
|
+
*
|
|
145
|
+
* @remarks Lowering this below the current `min` also lowers `min` to
|
|
146
|
+
* match, since `min` can never exceed `max`.
|
|
147
|
+
*/
|
|
96
148
|
set max(val) {
|
|
97
149
|
this._max = val >= 0 ? Math.max(val, 1) : defaultValues.max;
|
|
98
150
|
if (this._min > this._max)
|
|
99
151
|
this._min = this._max;
|
|
100
152
|
this.emit('change', 'max', this._max);
|
|
101
153
|
}
|
|
154
|
+
/** @defaultValue `1000` */
|
|
102
155
|
get maxQueue() {
|
|
103
156
|
return this._maxQueue;
|
|
104
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Negative values reset to the default instead of being applied;
|
|
160
|
+
* otherwise clamped up to at least `1`.
|
|
161
|
+
*/
|
|
105
162
|
set maxQueue(val) {
|
|
106
163
|
this._maxQueue = val >= 0 ? Math.max(val, 1) : defaultValues.maxQueue;
|
|
107
164
|
this.emit('change', 'maxQueue', this._maxQueue);
|
|
108
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* If `true`, a resource is validated via `factory.validate()` before
|
|
168
|
+
* being handed out (when the factory provides one).
|
|
169
|
+
*
|
|
170
|
+
* @defaultValue `true`
|
|
171
|
+
*/
|
|
109
172
|
get validation() {
|
|
110
173
|
return this._validation;
|
|
111
174
|
}
|
|
@@ -114,6 +177,15 @@ export class PoolOptions extends EventEmitter {
|
|
|
114
177
|
this._validation = !!val;
|
|
115
178
|
this.emit('change', 'validation', this._validation);
|
|
116
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Copies every recognized option from `values` onto this instance,
|
|
182
|
+
* emitting a `'change'` event per option (same as assigning each
|
|
183
|
+
* individually). Unknown keys are silently ignored.
|
|
184
|
+
*
|
|
185
|
+
* @param values - A plain `PoolConfiguration` object, or another
|
|
186
|
+
* `PoolOptions` instance to copy settings from (e.g. to clone one pool's
|
|
187
|
+
* configuration onto another).
|
|
188
|
+
*/
|
|
117
189
|
assign(values) {
|
|
118
190
|
const proto = Object.getPrototypeOf(this);
|
|
119
191
|
// A PoolOptions instance only owns underscored private fields, so its
|
package/pool-request.d.ts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import type { Pool } from './pool.js';
|
|
2
2
|
import type { Callback } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Internal bookkeeping for one pending `acquire()` call while it's queued
|
|
5
|
+
* or being processed. Not part of the public API.
|
|
6
|
+
*/
|
|
3
7
|
export declare class PoolRequest {
|
|
8
|
+
/** `Date.now()` when this request was created - used as `error` event's `requestTime`. */
|
|
4
9
|
created: number;
|
|
10
|
+
/** The caller's callback (or a resolved-Promise wrapper), invoked with the acquired resource or an error. */
|
|
5
11
|
callback: Callback;
|
|
6
12
|
options?: any;
|
|
13
|
+
/** The pending `acquireTimeoutMillis` timer, if one is running. */
|
|
7
14
|
timeoutHandle: any;
|
|
15
|
+
/** Set once `acquireTimeoutMillis` has elapsed for this request. */
|
|
8
16
|
timedOut: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Called when `acquireTimeoutMillis` elapses, before `request-timeout` is
|
|
19
|
+
* emitted and the callback is rejected. The pool uses it to drop the
|
|
20
|
+
* request from its queue, so `pending` no longer counts it.
|
|
21
|
+
*/
|
|
22
|
+
onTimeout?: () => void;
|
|
9
23
|
constructor(pool: Pool, callback?: Callback, options?: any);
|
|
24
|
+
/** Clears the pending timeout timer, if any (does not affect `timedOut`). */
|
|
10
25
|
stopTimout(): void;
|
|
11
26
|
}
|
package/pool-request.js
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
function noop() { }
|
|
2
|
+
/**
|
|
3
|
+
* Internal bookkeeping for one pending `acquire()` call while it's queued
|
|
4
|
+
* or being processed. Not part of the public API.
|
|
5
|
+
*/
|
|
2
6
|
export class PoolRequest {
|
|
7
|
+
/** `Date.now()` when this request was created - used as `error` event's `requestTime`. */
|
|
3
8
|
created;
|
|
9
|
+
/** The caller's callback (or a resolved-Promise wrapper), invoked with the acquired resource or an error. */
|
|
4
10
|
callback;
|
|
5
11
|
options;
|
|
12
|
+
/** The pending `acquireTimeoutMillis` timer, if one is running. */
|
|
6
13
|
timeoutHandle;
|
|
14
|
+
/** Set once `acquireTimeoutMillis` has elapsed for this request. */
|
|
7
15
|
timedOut = false;
|
|
16
|
+
/**
|
|
17
|
+
* Called when `acquireTimeoutMillis` elapses, before `request-timeout` is
|
|
18
|
+
* emitted and the callback is rejected. The pool uses it to drop the
|
|
19
|
+
* request from its queue, so `pending` no longer counts it.
|
|
20
|
+
*/
|
|
21
|
+
onTimeout;
|
|
8
22
|
constructor(pool, callback, options) {
|
|
9
23
|
this.created = Date.now();
|
|
10
24
|
this.callback = callback || noop;
|
|
@@ -13,11 +27,14 @@ export class PoolRequest {
|
|
|
13
27
|
this.timeoutHandle = setTimeout(() => {
|
|
14
28
|
this.timedOut = true;
|
|
15
29
|
this.stopTimout();
|
|
30
|
+
if (this.onTimeout)
|
|
31
|
+
this.onTimeout();
|
|
16
32
|
pool.emit('request-timeout');
|
|
17
33
|
this.callback(new Error('Request timed out'));
|
|
18
34
|
}, pool.options.acquireTimeoutMillis);
|
|
19
35
|
}
|
|
20
36
|
}
|
|
37
|
+
/** Clears the pending timeout timer, if any (does not affect `timedOut`). */
|
|
21
38
|
stopTimout() {
|
|
22
39
|
if (this.timeoutHandle)
|
|
23
40
|
clearTimeout(this.timeoutHandle);
|