Launch Week Day 3: Introducing Organization Notifications in Socket.Learn More
Socket
Book a DemoSign in
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
2.0.4
to
2.1.0
+9
-1
lib/generic-pool.js

@@ -97,2 +97,4 @@ var PriorityQueue = function(size) {

* Should idle resources be destroyed and recreated every idleTimeoutMillis? Default: true.
* @param {Bool} [factory.returnToHead=false]
* Returns released object to head of available objects list
* @returns {Object} An Object pool that works with the supplied `factory`.

@@ -112,2 +114,3 @@ */

draining = false,
returnToHead = factory.returnToHead || false,

@@ -341,3 +344,8 @@ // Prepare a logger function.

var objWithTimeout = { obj: obj, timeout: (new Date().getTime() + idleTimeoutMillis) };
availableObjects.push(objWithTimeout);
if(returnToHead){
availableObjects.splice(0, 0, objWithTimeout);
}
else{
availableObjects.push(objWithTimeout);
}
log("timeout: " + objWithTimeout.timeout, 'verbose');

@@ -344,0 +352,0 @@ dispense();

+5
-3
{
"name": "generic-pool",
"description": "Generic resource pooling for Node.JS",
"version": "2.0.4",
"version": "2.1.0",
"author": "James Cooper <james@bitmechanic.com>",

@@ -11,3 +11,4 @@ "contributors": [

{ "name": "Tom MacWright", "url" : "http://www.developmentseed.org/" },
{ "name": "Douglas Christopher Wilson", "email": "doug@somethingdoug.com", "url" : "http://somethingdoug.com/" }
{ "name": "Douglas Christopher Wilson", "email": "doug@somethingdoug.com", "url" : "http://somethingdoug.com/" },
{ "name": "calibr"}
],

@@ -26,3 +27,4 @@ "keywords": ["pool", "pooling", "throttle"],

"test": "expresso -I lib test/*.js"
}
},
"license": "MIT"
}

@@ -23,2 +23,6 @@ [![build status](https://secure.travis-ci.org/coopernurse/node-pool.png)](http://travis-ci.org/coopernurse/node-pool)

2.1.0 - June 19 2014
- Merged #72 - Add optional returnToHead flag, if true, resources are returned to head of queue (stack like
behaviour) upon release (contributed by calibr), also see #68 for further discussion.
2.0.4 - July 27 2013

@@ -195,2 +199,4 @@ - Merged #64 - Fix for not removing idle objects (contributed by PiotrWpl)

reapIntervalMillis : frequency to check for idle resources (default 1000),
returnToHead : boolean, if true the most recently released resources will be the first to be allocated.
This in effect turns the pool's behaviour from a queue into a stack. optional (default false)
priorityRange : int between 1 and x - if set, borrowers can specify their

@@ -326,3 +332,3 @@ relative priority in the queue if no resources are available.

Copyright (c) 2010-2013 James Cooper &lt;james@bitmechanic.com&gt;
Copyright (c) 2010-2014 James Cooper &lt;james@bitmechanic.com&gt;

@@ -329,0 +335,0 @@ Permission is hereby granted, free of charge, to any person obtaining

var poolModule = require('./lib/generic-pool.js');
var mysql = require('mysql');
var pool = poolModule.Pool({
name: 'mysql',
create: function (callback) {
console.log('create');
var connection = mysql.createConnection({
host: 'localhost',
user: 'test',
password: 'test',
database: 'test'
});
connection.connect(function () {
return callback(null, connection);
});
},
destroy: function (client) { // this is never called. ever
console.log('destroy');
client.destroy();
},
max: 3,
min: 2,
idleTimeoutMillis: 3000, //changed this to 3000
log: true
});
pool.query = function (query, data, callback) {
try {
pool.acquire(function (err, client) {
//called 3 times. never called again.
client.query(query, data, function (err, results, fields) {
try {
pool.release(client); // I've also tried pool.destroy(client);
return callback(err, results);
} catch (err) {
console.log(err)
}
});
});
} catch (err) {
console.log(err);
}
};
console.log("STARTED");
var i, count = 0;
for (i = 0; i < 10; i++) {
pool.query("select 1", [], function(err) {
count += 1;
console.log("finished " + count + " queries");
if (count === 10) {
console.log("STOPPING");
pool.drain();
}
});
}