File tree 4 files changed +62
-0
lines changed
4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ you spot any mistakes.
7
7
## HEAD
8
8
9
9
* Add code ` POOL_ENQUEUELIMIT ` to error reaching ` queueLimit `
10
+ * Add ` enqueue ` event to pool #716
10
11
* Add ` enqueue ` event to protocol and connection #381
11
12
* Blacklist unsupported connection flags #881
12
13
* Make only column names enumerable in ` RowDataPacket ` #549 #895
Original file line number Diff line number Diff line change @@ -348,6 +348,19 @@ addition to those options pools accept a few extras:
348
348
before returning an error from ` getConnection ` . If set to ` 0 ` , there is no
349
349
limit to the number of queued connection requests. (Default: ` 0 ` )
350
350
351
+ ## Pool events
352
+
353
+ ### enqueue
354
+
355
+ The pool will emit an ` enqueue ` event when a callback has been queued to wait for
356
+ an available connection.
357
+
358
+ ``` js
359
+ pool .on (' enqueue' , function () {
360
+ console .log (' Waiting for available connection slot' );
361
+ });
362
+ ```
363
+
351
364
## PoolCluster
352
365
353
366
PoolCluster provides multiple hosts connection. (group & retry & selector)
Original file line number Diff line number Diff line change @@ -201,6 +201,7 @@ Pool.prototype._enqueueCallback = function _enqueueCallback(callback) {
201
201
: callback ;
202
202
203
203
this . _connectionQueue . push ( cb ) ;
204
+ this . emit ( 'enqueue' ) ;
204
205
} ;
205
206
206
207
Pool . prototype . _purgeConnection = function _purgeConnection ( connection ) {
Original file line number Diff line number Diff line change
1
+ var assert = require ( 'assert' ) ;
2
+ var common = require ( '../../common' ) ;
3
+ var pool = common . createPool ( {
4
+ connectionLimit : 1 ,
5
+ port : common . fakeServerPort
6
+ } ) ;
7
+
8
+ var index = 0 ;
9
+ var server = common . createFakeServer ( ) ;
10
+
11
+ server . listen ( common . fakeServerPort , function ( err ) {
12
+ assert . ifError ( err ) ;
13
+
14
+ var count = 0 ;
15
+ pool . on ( 'enqueue' , function ( ) {
16
+ count ++ ;
17
+ } ) ;
18
+
19
+ pool . getConnection ( function ( err , connection ) {
20
+ assert . ifError ( err ) ;
21
+ assert . ok ( connection ) ;
22
+ assert . equal ( ++ index , 1 ) ;
23
+ assert . equal ( count , 0 ) ;
24
+
25
+ pool . getConnection ( function ( err ) {
26
+ assert . ifError ( err ) ;
27
+ assert . equal ( ++ index , 2 ) ;
28
+ assert . equal ( count , 2 ) ;
29
+
30
+ connection . release ( ) ;
31
+ } ) ;
32
+
33
+ pool . getConnection ( function ( err ) {
34
+ assert . ifError ( err ) ;
35
+ assert . equal ( ++ index , 3 ) ;
36
+ assert . equal ( count , 2 ) ;
37
+
38
+ connection . destroy ( ) ;
39
+ server . destroy ( ) ;
40
+ } ) ;
41
+
42
+ process . nextTick ( function ( ) {
43
+ assert . equal ( count , 2 ) ;
44
+ connection . release ( ) ;
45
+ } ) ;
46
+ } ) ;
47
+ } ) ;
You can’t perform that action at this time.
0 commit comments