lightning-pool 4.4.1 → 4.4.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/package.json +3 -2
- package/typings/abort-error.d.ts +2 -0
- package/typings/definitions.d.ts +34 -0
- package/typings/index.d.ts +6 -0
- package/typings/pool-options.d.ts +41 -0
- package/typings/pool-request.d.ts +11 -0
- package/typings/pool.d.ts +103 -0
- package/typings/resource-item.d.ts +11 -0
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.4.
|
|
4
|
+
"version": "4.4.3",
|
|
5
5
|
"author": "Panates Ltd.",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
@@ -21,10 +21,11 @@
|
|
|
21
21
|
"type": "module",
|
|
22
22
|
"main": "./cjs/index.js",
|
|
23
23
|
"module": "./esm/index.js",
|
|
24
|
-
"types": "./
|
|
24
|
+
"types": "./typings/index.d.ts",
|
|
25
25
|
"files": [
|
|
26
26
|
"cjs/",
|
|
27
27
|
"esm/",
|
|
28
|
+
"typings/",
|
|
28
29
|
"LICENSE",
|
|
29
30
|
"README.md"
|
|
30
31
|
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type Callback = (e?: unknown, ...args: any[]) => void;
|
|
2
|
+
export declare enum PoolState {
|
|
3
|
+
IDLE = 0,
|
|
4
|
+
STARTED = 1,
|
|
5
|
+
CLOSING = 2,
|
|
6
|
+
CLOSED = 3
|
|
7
|
+
}
|
|
8
|
+
export declare enum ResourceState {
|
|
9
|
+
IDLE = 0,
|
|
10
|
+
ACQUIRED = 1,
|
|
11
|
+
VALIDATION = 2
|
|
12
|
+
}
|
|
13
|
+
export interface PoolFactory<T = any> {
|
|
14
|
+
create(info?: {
|
|
15
|
+
tries: number;
|
|
16
|
+
maxRetries: number;
|
|
17
|
+
}): Promise<T> | T;
|
|
18
|
+
destroy(resource: T): Promise<void> | void;
|
|
19
|
+
reset?(resource: T): Promise<void> | void;
|
|
20
|
+
validate?(resource: T): Promise<void> | void;
|
|
21
|
+
}
|
|
22
|
+
export interface PoolConfiguration {
|
|
23
|
+
acquireMaxRetries?: number;
|
|
24
|
+
acquireRetryWait?: number;
|
|
25
|
+
acquireTimeoutMillis?: number;
|
|
26
|
+
fifo?: boolean;
|
|
27
|
+
idleTimeoutMillis?: number;
|
|
28
|
+
houseKeepInterval?: number;
|
|
29
|
+
min?: number;
|
|
30
|
+
minIdle?: number;
|
|
31
|
+
max?: number;
|
|
32
|
+
maxQueue?: number;
|
|
33
|
+
validation?: boolean;
|
|
34
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PoolConfiguration, PoolFactory } from './definitions.js';
|
|
2
|
+
import { Pool } from './pool.js';
|
|
3
|
+
export * from './abort-error.js';
|
|
4
|
+
export * from './definitions.js';
|
|
5
|
+
export * from './pool.js';
|
|
6
|
+
export declare function createPool<T = any>(factory: PoolFactory<T>, config?: PoolConfiguration): Pool<T>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { PoolConfiguration } from './definitions.js';
|
|
3
|
+
import { Pool } from './pool.js';
|
|
4
|
+
export declare class PoolOptions extends EventEmitter {
|
|
5
|
+
readonly pool: Pool;
|
|
6
|
+
private _acquireMaxRetries;
|
|
7
|
+
private _acquireRetryWait;
|
|
8
|
+
private _acquireTimeoutMillis;
|
|
9
|
+
private _fifo;
|
|
10
|
+
private _idleTimeoutMillis;
|
|
11
|
+
private _houseKeepInterval;
|
|
12
|
+
private _min;
|
|
13
|
+
private _minIdle;
|
|
14
|
+
private _max;
|
|
15
|
+
private _maxQueue;
|
|
16
|
+
private _validation;
|
|
17
|
+
constructor(pool: Pool);
|
|
18
|
+
get acquireMaxRetries(): number;
|
|
19
|
+
set acquireMaxRetries(val: number);
|
|
20
|
+
get acquireRetryWait(): number;
|
|
21
|
+
set acquireRetryWait(val: number);
|
|
22
|
+
get acquireTimeoutMillis(): number;
|
|
23
|
+
set acquireTimeoutMillis(val: number);
|
|
24
|
+
get fifo(): boolean;
|
|
25
|
+
set fifo(val: boolean);
|
|
26
|
+
get idleTimeoutMillis(): number;
|
|
27
|
+
set idleTimeoutMillis(val: number);
|
|
28
|
+
get houseKeepInterval(): number;
|
|
29
|
+
set houseKeepInterval(val: number);
|
|
30
|
+
get min(): number;
|
|
31
|
+
set min(val: number);
|
|
32
|
+
get minIdle(): number;
|
|
33
|
+
set minIdle(val: number);
|
|
34
|
+
get max(): number;
|
|
35
|
+
set max(val: number);
|
|
36
|
+
get maxQueue(): number;
|
|
37
|
+
set maxQueue(val: number);
|
|
38
|
+
get validation(): boolean;
|
|
39
|
+
set validation(val: boolean);
|
|
40
|
+
assign(values: PoolConfiguration | PoolOptions): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Callback } from './definitions.js';
|
|
2
|
+
import { Pool } from './pool.js';
|
|
3
|
+
export declare class PoolRequest {
|
|
4
|
+
created: number;
|
|
5
|
+
callback: Callback;
|
|
6
|
+
options?: any;
|
|
7
|
+
timeoutHandle: any;
|
|
8
|
+
timedOut: boolean;
|
|
9
|
+
constructor(pool: Pool, callback?: Callback, options?: any);
|
|
10
|
+
stopTimout(): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { Callback, PoolConfiguration, PoolFactory, PoolState } from './definitions.js';
|
|
3
|
+
import { PoolOptions } from './pool-options.js';
|
|
4
|
+
export declare class Pool<T = any> extends EventEmitter {
|
|
5
|
+
private readonly _options;
|
|
6
|
+
private readonly _factory;
|
|
7
|
+
private _requestQueue;
|
|
8
|
+
private _allResources;
|
|
9
|
+
private _acquiredResources;
|
|
10
|
+
private _idleResources;
|
|
11
|
+
private _creating;
|
|
12
|
+
private _requestsProcessing;
|
|
13
|
+
private _state;
|
|
14
|
+
private _houseKeepTimer;
|
|
15
|
+
private _closeWaitTimer;
|
|
16
|
+
constructor(factory: PoolFactory<T>, config?: PoolConfiguration);
|
|
17
|
+
/**
|
|
18
|
+
* Returns Pool options
|
|
19
|
+
*/
|
|
20
|
+
get options(): PoolOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Returns number of resources that are currently acquired
|
|
23
|
+
*/
|
|
24
|
+
get acquired(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Returns number of unused resources in the pool
|
|
27
|
+
*/
|
|
28
|
+
get available(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Returns number of resources currently creating
|
|
31
|
+
*/
|
|
32
|
+
get creating(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Returns number of callers waiting to acquire a resource
|
|
35
|
+
*/
|
|
36
|
+
get pending(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Returns number of resources in the pool
|
|
39
|
+
* regardless of whether they are idle or in use
|
|
40
|
+
*/
|
|
41
|
+
get size(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Returns state of the pool
|
|
44
|
+
*/
|
|
45
|
+
get state(): PoolState;
|
|
46
|
+
/**
|
|
47
|
+
* Starts the pool and begins creating of resources, starts house keeping and any other internal logic.
|
|
48
|
+
* Note: This method is not need to be called. Pool instance will automatically be started when acquire() method is called
|
|
49
|
+
*/
|
|
50
|
+
start(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Shuts down the pool and destroys all resources.
|
|
53
|
+
*/
|
|
54
|
+
close(callback?: Callback): void;
|
|
55
|
+
close(terminateWait: number, callback?: Callback): void;
|
|
56
|
+
close(force: boolean, callback?: Callback): void;
|
|
57
|
+
closeAsync(): Promise<void>;
|
|
58
|
+
closeAsync(terminateWait: number): Promise<void>;
|
|
59
|
+
closeAsync(force: boolean): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Acquires `resource` from the pool or create a new one
|
|
62
|
+
*/
|
|
63
|
+
acquire(): Promise<T>;
|
|
64
|
+
acquire(callback: Callback): void;
|
|
65
|
+
/**
|
|
66
|
+
* Releases an allocated `resource` and let it back to pool.
|
|
67
|
+
*/
|
|
68
|
+
release(resource: T, callback?: Callback): void;
|
|
69
|
+
/**
|
|
70
|
+
* Async version of release().
|
|
71
|
+
*/
|
|
72
|
+
releaseAsync(resource: T): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Releases, destroys and removes any `resource` from `Pool`.
|
|
75
|
+
*/
|
|
76
|
+
destroy(resource: T, callback?: Callback): any;
|
|
77
|
+
/**
|
|
78
|
+
* Async version of destroy().
|
|
79
|
+
*/
|
|
80
|
+
destroyAsync(resource: T): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Returns if a `resource` has been acquired from the pool and not yet released or destroyed.
|
|
83
|
+
*/
|
|
84
|
+
isAcquired(resource: T): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Returns if the pool contains a `resource`
|
|
87
|
+
*/
|
|
88
|
+
includes(resource: T): boolean;
|
|
89
|
+
private _processNextRequest;
|
|
90
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Creates new resource
|
|
93
|
+
*/
|
|
94
|
+
private _createResource;
|
|
95
|
+
private _setHouseKeep;
|
|
96
|
+
private _houseKeep;
|
|
97
|
+
private _ensureMin;
|
|
98
|
+
private _itemSetAcquired;
|
|
99
|
+
private _itemDetach;
|
|
100
|
+
private _itemSetIdle;
|
|
101
|
+
private _itemDestroy;
|
|
102
|
+
private _itemValidate;
|
|
103
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DoublyLinked } from 'doublylinked';
|
|
2
|
+
import { ResourceState } from './definitions.js';
|
|
3
|
+
export declare class ResourceItem<T> {
|
|
4
|
+
state: ResourceState;
|
|
5
|
+
acquiredNode?: DoublyLinked.Node;
|
|
6
|
+
idleNode?: DoublyLinked.Node;
|
|
7
|
+
resource: T;
|
|
8
|
+
idleTime: number;
|
|
9
|
+
destroyed: boolean;
|
|
10
|
+
constructor(resource: T);
|
|
11
|
+
}
|