generic-pool
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -118,2 +118,4 @@ var PriorityQueue = function(size) { | ||
* | ||
* This should be called within an acquire() block as an alternative to release(). | ||
* | ||
* @param {Object} obj | ||
@@ -124,2 +126,5 @@ * The acquired item to be destoyed. | ||
count -= 1; | ||
availableObjects = availableObjects.filter(function(objWithTimeout) { | ||
return (objWithTimeout.obj !== obj); | ||
}); | ||
factory.destroy(obj); | ||
@@ -132,6 +137,6 @@ }; | ||
function removeIdle() { | ||
var toKeep = [], | ||
var toRemove = [], | ||
now = new Date().getTime(), | ||
i, | ||
al, | ||
al, tr, | ||
timeout; | ||
@@ -145,14 +150,15 @@ | ||
timeout = availableObjects[i].timeout; | ||
if (now < timeout) { | ||
// Client hasn't timed out, so keep it. | ||
toKeep.push(availableObjects[i]); | ||
} else { | ||
// The client timed out, call its destroyer. | ||
if (now >= timeout) { | ||
// Client timed out, so destroy it. | ||
log("removeIdle() destroying obj - now:" + now + " timeout:" + timeout, 'verbose'); | ||
me.destroy(availableObjects[i].obj); | ||
} | ||
toRemove.push(availableObjects[i].obj); | ||
} | ||
} | ||
for (i = 0, tr = toRemove.length; i < tr; i += 1) { | ||
me.destroy(toRemove[i]); | ||
} | ||
// Replace the available items with the ones to keep. | ||
availableObjects = toKeep; | ||
al = availableObjects.length; | ||
@@ -159,0 +165,0 @@ |
{ | ||
"name": "generic-pool", | ||
"description": "Generic resource pooling for Node.JS", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"author": "James Cooper <james@bitmechanic.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -13,2 +13,5 @@ | ||
1.0.10 - May 3 2012 | ||
- Merged #35 (Remove client from availbleObjects on destroy(client) - contributed by blax) | ||
1.0.9 - Dec 18 2011 | ||
@@ -15,0 +18,0 @@ - Merged #25 (add getName() - contributed by BryanDonovan) |
@@ -322,4 +322,23 @@ var assert = require('assert'); | ||
}); | ||
}, | ||
'removes from available objects on destroy': function(beforeExit){ | ||
var destroyCalled = false; | ||
var factory = { | ||
name: 'test', | ||
create: function(callback) {callback(null, {})}, | ||
destroy: function(client) {destroyCalled = true}, | ||
max: 2, | ||
idleTimeoutMillis: 100 | ||
}; | ||
var pool = poolModule.Pool(factory); | ||
pool.acquire(function(err, obj){ | ||
pool.destroy(obj); | ||
}); | ||
assert.equal(destroyCalled, true); | ||
assert.equal(pool.availableObjectsCount(), 0); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
31226
628
208