@@ -13,7 +13,7 @@ const {
1313 InvalidArgumentError
1414} = require ( '../core/errors' )
1515const util = require ( '../core/util' )
16- const { kUrl } = require ( '../core/symbols' )
16+ const { kUrl, kMaxFree } = require ( '../core/symbols' )
1717const buildConnector = require ( '../core/connect' )
1818
1919const kOptions = Symbol ( 'options' )
@@ -37,6 +37,7 @@ class Pool extends PoolBase {
3737 autoSelectFamilyAttemptTimeout,
3838 allowH2,
3939 clientTtl,
40+ maxFree = Infinity ,
4041 ...options
4142 } = { } ) {
4243 if ( connections != null && ( ! Number . isFinite ( connections ) || connections < 0 ) ) {
@@ -51,6 +52,10 @@ class Pool extends PoolBase {
5152 throw new InvalidArgumentError ( 'connect must be a function or an object' )
5253 }
5354
55+ if ( typeof maxFree !== 'number' || Number . isNaN ( maxFree ) || maxFree <= 0 ) {
56+ throw new InvalidArgumentError ( 'maxFree must be a number greater than 0' )
57+ }
58+
5459 if ( typeof connect !== 'function' ) {
5560 connect = buildConnector ( {
5661 ...tls ,
@@ -67,11 +72,12 @@ class Pool extends PoolBase {
6772
6873 this [ kConnections ] = connections || null
6974 this [ kUrl ] = util . parseOrigin ( origin )
70- this [ kOptions ] = { ...util . deepClone ( options ) , connect, allowH2, clientTtl }
75+ this [ kOptions ] = { ...util . deepClone ( options ) , connect, allowH2, clientTtl, maxFree }
7176 this [ kOptions ] . interceptors = options . interceptors
7277 ? { ...options . interceptors }
7378 : undefined
7479 this [ kFactory ] = factory
80+ this [ kMaxFree ] = maxFree
7581
7682 this . on ( 'connect' , ( origin , targets ) => {
7783 if ( clientTtl != null && clientTtl > 0 ) {
0 commit comments