lib/PromisePool.js
function PromisePool(opts) {
    this._opts = {
        // Configuration options
        name:               opts.name || 'pool',
        idleTimeoutMillis:  opts.idleTimeoutMillis || 30000,
        reapInterval:       opts.reapIntervalMillis || 1000,
        drainCheckInterval: opts.drainCheckIntervalMillis || 100,
        refreshIdle:        ('refreshIdle' in opts) ? opts.refreshIdle : true,
        returnToHead:       opts.returnToHead || false,
        max:                parseInt(opts.max, 10),
        min:                parseInt(opts.min, 10),

        // Client management methods.
        create:     opts.create,
        destroy:    opts.destroy,
        validate:   opts.validate || function(){ return true; },
        onRelease:  opts.onRelease
    };

    this._availableObjects = [];
    this._waitingClients = new PriorityQueue(opts.priorityRange || 1);
    this._count = 0;
    this._removeIdleScheduled = false;
    this._removeIdleTimer = null;
    this._draining = false;

    // Prepare a logger function.
    if (opts.log instanceof Function) {
        this._log = opts.log;
    }
    else if (opts.log) {
        this._log = _logger.bind(this);
    }
    else {
        this._log = function(){};
    }

    // Clean up some of the inputs.
    this._validate = opts.validate || function(){ return true; };
    this._opts.max = Math.max(isNaN(this._opts.max) ? 1 : this._opts.max, 1);
    this._opts.min = Math.min(isNaN(this._opts.min) ? 0 : this._opts.min, this._opts.max-1);

    // Finally, ensure a minimum number of connections right out of the gate.
    _ensureMinimum.call(this);
}
function PromisePool(opts) {
    this._opts = {
        // Configuration options
        name:               opts.name || 'pool',
        idleTimeoutMillis:  opts.idleTimeoutMillis || 30000,
        reapInterval:       opts.reapIntervalMillis || 1000,
        drainCheckInterval: opts.drainCheckIntervalMillis || 100,
        refreshIdle:        ('refreshIdle' in opts) ? opts.refreshIdle : true,
        returnToHead:       opts.returnToHead || false,
        max:                parseInt(opts.max, 10),
        min:                parseInt(opts.min, 10),

        // Client management methods.
        create:     opts.create,
        destroy:    opts.destroy,
        validate:   opts.validate || function(){ return true; },
        onRelease:  opts.onRelease
    };

    this._availableObjects = [];
    this._waitingClients = new PriorityQueue(opts.priorityRange || 1);
    this._count = 0;
    this._removeIdleScheduled = false;
    this._removeIdleTimer = null;
    this._draining = false;

    // Prepare a logger function.
    if (opts.log instanceof Function) {
        this._log = opts.log;
    }
    else if (opts.log) {
        this._log = _logger.bind(this);
    }
    else {
        this._log = function(){};
    }

    // Clean up some of the inputs.
    this._validate = opts.validate || function(){ return true; };
    this._opts.max = Math.max(isNaN(this._opts.max) ? 1 : this._opts.max, 1);
    this._opts.min = Math.min(isNaN(this._opts.min) ? 0 : this._opts.min, this._opts.max-1);

    // Finally, ensure a minimum number of connections right out of the gate.
    _ensureMinimum.call(this);
}
function PromisePool ( opts ) { this . _opts = { // Configuration options name : opts . name || 'pool' , idleTimeoutMillis : opts . idleTimeoutMillis || 30000 , reapInterval : opts . reapIntervalMillis || 1000 , drainCheckInterval : opts . drainCheckIntervalMillis || 100 , refreshIdle : ( 'refreshIdle' in opts ) ? opts . refreshIdle : true , returnToHead : opts . returnToHead || false , max : parseInt ( opts . max , 10 ) , min : parseInt ( opts . min , 10 ) , // Client management methods. create : opts . create , destroy : opts . destroy , validate : opts . validate || function ( ) { return true ; } , onRelease : opts . onRelease } ; this . _availableObjects = [ ] ; this . _waitingClients = new PriorityQueue ( opts . priorityRange || 1 ) ; this . _count = 0 ; this . _removeIdleScheduled = false ; this . _removeIdleTimer = null ; this . _draining = false ; // Prepare a logger function. if ( opts . log instanceof Function ) { this . _log = opts . log ; } else if ( opts . log ) { this . _log = _logger . bind ( this ) ; } else { this . _log = function ( ) { } ; } // Clean up some of the inputs. this . _validate = opts . validate || function ( ) { return true ; } ; this . _opts . max = Math . max ( isNaN ( this . _opts . max ) ? 1 : this . _opts . max , 1 ) ; this . _opts . min = Math . min ( isNaN ( this . _opts . min ) ? 0 : this . _opts . min , this . _opts . max - 1 ) ; // Finally, ensure a minimum number of connections right out of the gate. _ensureMinimum . call ( this ) ; }
Constructs a new pool with the provided factory options.

@constructor
@classdesc
A resource pooling class with a promise-based API.

@param {PromisePool.Factory} opts
The connection factory which specifies the functionality for the pool.
Constructs a new pool with the provided factory options .