Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

generic-pool

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generic-pool - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

tsconfig.json

3

CHANGELOG.md
# Change Log
## [3.4.0] - December 27 2017
- #218 fix numerous docblock annotations and minor errors in internal classes (@geovanisouza92)
## [3.3.0] - December 27 2017

@@ -4,0 +7,0 @@ - add `use` method to simplify basic pool usage (@san00)

22

lib/Deque.js

@@ -16,6 +16,6 @@ "use strict";

* removes and returns the first element from the queue
* @return {[type]} [description]
* @return {any} [description]
*/
shift() {
if (this._length === 0) {
if (this.length === 0) {
return undefined;

@@ -32,4 +32,4 @@ }

* adds one elemts to the beginning of the queue
* @param {[type]} element [description]
* @return {[type]} [description]
* @param {any} element [description]
* @return {any} [description]
*/

@@ -44,4 +44,4 @@ unshift(element) {

* adds one to the end of the queue
* @param {[type]} element [description]
* @return {[type]} [description]
* @param {any} element [description]
* @return {any} [description]
*/

@@ -58,3 +58,3 @@ push(element) {

pop() {
if (this._length === 0) {
if (this.length === 0) {
return undefined;

@@ -83,6 +83,6 @@ }

* get a reference to the item at the head of the queue
* @return {element} [description]
* @return {any} [description]
*/
get head() {
if (this._list.length === 0) {
if (this.length === 0) {
return undefined;

@@ -96,6 +96,6 @@ }

* get a reference to the item at the tail of the queue
* @return {element} [description]
* @return {any} [description]
*/
get tail() {
if (this._list.length === 0) {
if (this.length === 0) {
return undefined;

@@ -102,0 +102,0 @@ }

@@ -18,4 +18,4 @@ "use strict";

/**
* @param {Object} doublyLinkedListNode a node that is part of a doublyLinkedList
* @param {Boolean} reverse is this a reverse iterator? default: false
* @param {Object} doublyLinkedList a node that is part of a doublyLinkedList
* @param {Boolean} [reverse=false] is this a reverse iterator? default: false
*/

@@ -89,3 +89,2 @@ constructor(doublyLinkedList, reverse) {

* the required next/prev/head/tail rather than all of them
* @param {[type]} node [description]
* @return {Boolean} [description]

@@ -92,0 +91,0 @@ */

@@ -6,2 +6,3 @@ "use strict";

super(message);
// @ts-ignore
this.name = this.constructor.name;

@@ -8,0 +9,0 @@ this.message = message;

@@ -10,2 +10,6 @@ "use strict";

const PooledResource = require("./PooledResource");
const DefaultEvictor = require("./DefaultEvictor");
const Deque = require("./Deque");
const PriorityQueue = require("./PriorityQueue");
const DequeIterator = require("./DequeIterator");

@@ -24,2 +28,5 @@ const reflector = require("./utils").reflector;

*
* @param {typeof DefaultEvictor} Evictor
* @param {typeof Deque} Deque
* @param {typeof PriorityQueue} PriorityQueue
* @param {Object} factory

@@ -36,2 +43,3 @@ * Factory to be used for generating and destroying the items.

* If it should be removed from pool.
* @param {Object} options
*/

@@ -72,3 +80,3 @@ constructor(Evictor, Deque, PriorityQueue, factory, options) {

* TODO: replace with LinkedList backed array
* @type {Array}
* @type {Deque}
*/

@@ -97,3 +105,3 @@ this._availableObjects = new Deque();

* All objects associated with this pool in any state (except destroyed)
* @type {PooledResourceCollection}
* @type {Set}
*/

@@ -110,3 +118,3 @@ this._allObjects = new Set();

* Infinitely looping iterator over available object
* @type {DLLArrayIterator}
* @type {DequeIterator}
*/

@@ -119,3 +127,3 @@ this._evictionIterator = this._availableObjects.iterator();

* handle for setTimeout for next eviction run
* @type {[type]}
* @type {(number|null)}
*/

@@ -194,3 +202,3 @@ this._scheduledEviction = null;

this._dispatchPooledResourceToNextWaitingClient(pooledResource);
return;
return false;
}

@@ -258,4 +266,4 @@

* puts the PooledResource back on the available list
* @param {[type]} pooledResource [description]
* @return {[type]} [description]
* @param {PooledResource} pooledResource [description]
* @return {Boolean} [description]
*/

@@ -385,2 +393,3 @@ _dispatchPooledResourceToNextWaitingClient(pooledResource) {

if (this._config.evictionRunIntervalMillis > 0) {
// @ts-ignore
this._scheduledEviction = setTimeout(() => {

@@ -394,3 +403,5 @@ this._evict();

_descheduleEvictorRun() {
clearTimeout(this._scheduledEviction);
if (this._scheduledEviction) {
clearTimeout(this._scheduledEviction);
}
this._scheduledEviction = null;

@@ -416,9 +427,3 @@ }

*
* @param {Function} callback
* Callback function to be called after the acquire is successful.
* If there is an error preventing the acquisition of resource, an error will
* be the first parameter, else it will be null.
* The acquired resource will be the second parameter.
*
* @param {Number} priority
* @param {Number} [priority=0]
* Optional. Integer between 0 and (priorityRange - 1). Specifies the priority

@@ -497,3 +502,3 @@ * of the caller if there are no available resources. Lower numbers mean higher

*
* @param {Object} obj
* @param {Object} resource
* The acquired object to be put back to the pool.

@@ -616,2 +621,3 @@ */

// Destroy existing resources
// @ts-ignore
for (const resource of this._availableObjects) {

@@ -682,3 +688,3 @@ this._destroy(resource);

* number of resources that are currently acquired
* @return {[type]} [description]
* @return {Number} [description]
*/

@@ -691,3 +697,3 @@ get borrowed() {

* number of waiting acquire calls
* @return {[type]} [description]
* @return {Number} [description]
*/

@@ -700,3 +706,3 @@ get pending() {

* maximum size of the pool
* @return {[type]} [description]
* @return {Number} [description]
*/

@@ -709,3 +715,3 @@ get max() {

* minimum size of the pool
* @return {[type]} [description]
* @return {Number} [description]
*/

@@ -712,0 +718,0 @@ get min() {

@@ -7,8 +7,8 @@ "use strict";

/**
* @param {Object} config
* @param {Object} opts
* configuration for the pool
* @param {Number} config.max
* @param {Number} [opts.max=null]
* 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
* @param {Number} [opts.min=null]
* Minimum number of items in pool (including in-use). Default: 0.

@@ -18,26 +18,31 @@ * When the pool is created, or a resource destroyed, this minimum will

* resource will be created and added to the pool.
* @param {Number} config.maxWaitingClients
* @param {Number} [opts.maxWaitingClients=null]
* maximum number of queued requests allowed after which acquire calls will be rejected
* @param {Number} config.acquireTimeoutMillis
* @param {Boolean} [opts.testOnBorrow=false]
* should the pool validate resources before giving them to clients. Requires that either
* `factory.validate` or `factory.validateAsync` to be specified.
* @param {Boolean} [opts.testOnReturn=false]
* should the pool validate resources before returning them to the pool.
* @param {Number} [opts.acquireTimeoutMillis=null]
* Delay in milliseconds after which the an `acquire` call will fail. optional.
* Default: undefined. Should be positive and non-zero
* @param {Number} config.priorityRange
* @param {Number} [opts.priorityRange=1]
* The range from 1 to be treated as a valid priority
* @param {Bool} [config.fifo=true]
* @param {Boolean} [opts.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]
* @param {Boolean} [opts.autostart=true]
* Should the pool start creating resources etc once the constructor is called
* @param {Number} opts.evictionRunIntervalMillis
* @param {Number} [opts.evictionRunIntervalMillis=0]
* How often to run eviction checks. Default: 0 (does not run).
* @param {Number} opts.numTestsPerEvictionRun
* @param {Number} [opts.numTestsPerEvictionRun=3]
* Number of resources to check each eviction run. Default: 3.
* @param {Number} opts.softIdleTimeoutMillis
* @param {Number} [opts.softIdleTimeoutMillis=-1]
* amount of time an object may sit idle in the pool before it is eligible
* for eviction by the idle object evictor (if any), with the extra condition
* that at least "min idle" object instances remain in the pool. Default -1 (nothing can get evicted)
* @param {Number} opts.idleTimeoutMillis
* @param {Number} [opts.idleTimeoutMillis=30000]
* the minimum amount of time that an object may sit idle in the pool before it is eligible for eviction
* due to idle time. Supercedes "softIdleTimeoutMillis" Default: 30000
* @param {Promise} [config.Promise=Promise]
* @param {typeof Promise} [opts.Promise=Promise]
* What promise implementation should the pool use, defaults to native promises.

@@ -68,2 +73,3 @@ */

if (opts.acquireTimeoutMillis) {
// @ts-ignore
this.acquireTimeoutMillis = parseInt(opts.acquireTimeoutMillis, 10);

@@ -73,6 +79,9 @@ }

if (opts.maxWaitingClients) {
// @ts-ignore
this.maxWaitingClients = parseInt(opts.maxWaitingClients, 10);
}
// @ts-ignore
this.max = parseInt(opts.max, 10);
// @ts-ignore
this.min = parseInt(opts.min, 10);

@@ -79,0 +88,0 @@

@@ -12,2 +12,3 @@ "use strict";

this._size = Math.max(+size | 0, 1);
/** @type {Queue[]} */
this._slots = [];

@@ -14,0 +15,0 @@ // initialize arrays to hold queue elements

@@ -18,3 +18,3 @@ "use strict";

* node for our rejection handler
* @param {[type]} item [description]
* @param {any} resourceRequest [description]
*/

@@ -21,0 +21,0 @@ push(resourceRequest) {

@@ -13,4 +13,4 @@ "use strict";

*
* @param {PooledResource} pooledResource the PooledResource this loan belongs to
* @return {[type]} [description]
* @param {any} pooledResource the PooledResource this loan belongs to
* @return {any} [description]
*/

@@ -17,0 +17,0 @@ constructor(pooledResource, Promise) {

@@ -55,3 +55,5 @@ "use strict";

removeTimeout() {
clearTimeout(this._timeout);
if (this._timeout) {
clearTimeout(this._timeout);
}
this._timeout = null;

@@ -58,0 +60,0 @@ }

{
"name": "generic-pool",
"description": "Generic resource pooling for Node.JS",
"version": "3.3.0",
"version": "3.4.0",
"author": "James Cooper <james@bitmechanic.com>",

@@ -67,2 +67,3 @@ "contributors": [

"devDependencies": {
"@types/node": "^8.5.1",
"eslint": "^4.9.0",

@@ -73,3 +74,4 @@ "eslint-config-prettier": "^2.6.0",

"prettier": "^1.7.4",
"tap": "^8.0.0"
"tap": "^8.0.0",
"typescript": "^2.6.2"
},

@@ -76,0 +78,0 @@ "engines": {

@@ -0,1 +1,3 @@

const Pool = require("../lib/Pool");
/**

@@ -30,4 +32,4 @@ * Generic class for handling creation of resources

*
* @param {[type]} pool [description]
* @return {[type]} [description]
* @param {Pool} pool [description]
* @return {Promise} [description]
*/

@@ -34,0 +36,0 @@ exports.stopPool = function(pool) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc