generic-pool
Advanced tools
Comparing version 3.0.0-alpha.4 to 3.0.0-alpha.5
11
index.js
const Pool = require('./lib/Pool') | ||
const PoolDefaults = require('./lib/PoolDefaults') | ||
module.exports = { | ||
Pool: Pool, | ||
PoolDefaults: PoolDefaults | ||
} | ||
exports.Pool = Pool | ||
exports.createPool = function(factory, config){ | ||
return new Pool(factory, config) | ||
} | ||
@@ -5,3 +5,4 @@ 'use strict' | ||
const PoolDefaults = require('./PoolDefaults') | ||
const factoryValidator = require('./factoryValidator') | ||
const PoolOptions = require('./PoolOptions') | ||
const PriorityQueue = require('./PriorityQueue') | ||
@@ -34,72 +35,12 @@ const ResourceRequest = require('./ResourceRequest') | ||
* If it should be removed from pool. | ||
* | ||
* @param {Object} config | ||
* configuration for the pool | ||
* @param {Number} config.max | ||
* Maximum number of items that can exist at the same time. Default: 1. | ||
* Any further acquire requests will be pushed to the waiting list. | ||
* @param {Number} config.min | ||
* Minimum number of items in pool (including in-use). Default: 0. | ||
* When the pool is created, or a resource destroyed, this minimum will | ||
* be checked. If the pool resource count is below the minimum, a new | ||
* resource will be created and added to the pool. | ||
* @param {Number} config.maxWaitingClients | ||
* maximum number of queued requests allowed after which acquire calls will be rejected | ||
* @param {Number} config.idleTimeoutMillis | ||
* Delay in milliseconds after the idle items in the pool will be destroyed. | ||
* And idle item is that is not acquired yet. Waiting items doesn't count here. | ||
* @param {Number} config.reapIntervalMillis | ||
* Cleanup is scheduled in every `config.reapIntervalMillis` milliseconds. | ||
* @param {Number} config.acquireTimeoutMillis | ||
* Delay in milliseconds after which the an `acquire` call will fail. optional. | ||
* Default: undefined. Should be positive and non-zero | ||
* @param {Number} config.priorityRange | ||
* The range from 1 to be treated as a valid priority | ||
* @param {RefreshIdle} config.refreshIdle | ||
* Should idle resources be destroyed and recreated every idleTimeoutMillis? Default: true. | ||
* @param {Bool} [config.fifo=true] | ||
* Sets whether the pool has LIFO (last in, first out) behaviour with respect to idle objects. | ||
* if false then pool has FIFO behaviour | ||
* @param {Bool} [config.autostart=true] | ||
* Should the pool start creating resources etc once the constructor is called | ||
* @param {Promise} [config.Promise=Promise] | ||
* What promise implementation should the pool use, defaults to native promises. | ||
*/ | ||
constructor (factory, config) { | ||
constructor (factory, options) { | ||
super() | ||
const poolDefaults = new PoolDefaults() | ||
factoryValidator(factory) | ||
const _config = config || {} | ||
this._config = new PoolOptions(options) | ||
this._config = {} | ||
this._Promise = this._config.Promise | ||
// defaults | ||
this._config.idleTimeoutMillis = _config.idleTimeoutMillis || poolDefaults.idleTimeoutMillis | ||
this._config.fifo = (typeof _config.fifo === 'boolean') ? _config.fifo : poolDefaults.fifo | ||
this._config.refreshIdle = ('refreshIdle' in _config) ? _config.refreshIdle : poolDefaults.refreshIdle | ||
this._config.reapInterval = _config.reapIntervalMillis || poolDefaults.reapIntervalMillis | ||
this._config.priorityRange = _config.priorityRange || poolDefaults.priorityRange | ||
this._config.testOnBorrow = (typeof _config.testOnBorrow === 'boolean') ? _config.testOnBorrow : poolDefaults.testOnBorrow | ||
this._config.testOnReturn = (typeof _config.testOnReturn === 'boolean') ? _config.testOnReturn : poolDefaults.testOnReturn | ||
this._config.autostart = (typeof _config.autostart === 'boolean') ? _config.autostart : poolDefaults.autostart | ||
if (_config.acquireTimeoutMillis) { | ||
this._config.acquireTimeoutMillis = parseInt(_config.acquireTimeoutMillis, 10) | ||
} | ||
if (_config.maxWaitingClients) { | ||
this._config.maxWaitingClients = parseInt(_config.maxWaitingClients, 10) | ||
} | ||
this._config.max = parseInt(_config.max, 10) | ||
this._config.min = parseInt(_config.min, 10) | ||
this._config.max = Math.max(isNaN(this._config.max) ? 1 : this._config.max, 1) | ||
this._config.min = Math.min(isNaN(this._config.min) ? 0 : this._config.min, this._config.max) | ||
this._Promise = (typeof _config.Promise === 'object') ? _config.Promise : poolDefaults.Promise | ||
this._factory = factory | ||
@@ -106,0 +47,0 @@ this._draining = false |
{ | ||
"name": "generic-pool", | ||
"description": "Generic resource pooling for Node.JS", | ||
"version": "3.0.0-alpha.4", | ||
"version": "3.0.0-alpha.5", | ||
"author": "James Cooper <james@bitmechanic.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -30,3 +30,3 @@ [![build status](https://secure.travis-ci.org/coopernurse/node-pool.png)](http://travis-ci.org/coopernurse/node-pool) | ||
```js | ||
var Pool = require('generic-pool').Pool; | ||
var genericPool = require('generic-pool'); | ||
var DbDriver = require('some-db-driver'); | ||
@@ -61,3 +61,3 @@ | ||
var myPool = new Pool(factory, opts) | ||
var myPool = genericPool.createPool(factory, opts) | ||
@@ -97,6 +97,12 @@ /** | ||
### Constructor | ||
The `Pool` constructor takes two arguments: | ||
### Creating a pool | ||
Whilst it is possible to directly instantiate the Pool class directly, it is recommended to use the `createPool` function exported by module as the constructor method signature may change in the future. | ||
### createPool | ||
The createPool function takes two arguments: | ||
- `factory` : an object containing functions to create/destroy/test resources for the `Pool` | ||
@@ -106,3 +112,4 @@ - `opts` : an optional object/dictonary to allow configuring/altering behaviour the of the `Pool` | ||
```js | ||
var pool = new Pool(factory, opts) | ||
const genericPool = require('generic-pool') | ||
const pool = genericPool.createPool(factory, opts) | ||
``` | ||
@@ -230,3 +237,3 @@ | ||
} | ||
var pool = new Pool(someFactory,opts); | ||
var pool = genericPool.createPool(someFactory,opts); | ||
@@ -318,3 +325,3 @@ // acquire connection - no priority specified - will go onto lowest priority queue | ||
The following functions will let you get information about the pool: | ||
The following properties will let you get information about the pool: | ||
@@ -321,0 +328,0 @@ ```js |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77765
27
1872
378