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

generic-pool

Package Overview
Dependencies
Maintainers
1
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 1.0.7 to 1.0.8

37

lib/generic-pool.js

@@ -0,1 +1,2 @@

var sys = require('sys');
var PriorityQueue = function(size) {

@@ -123,6 +124,6 @@ var me = {}, slots, i, total = null;

factory.destroy(obj);
}
};
/**
* Checks and removes the available (idle) clients that has timed out.
* Checks and removes the available (idle) clients that have timed out.
*/

@@ -146,3 +147,3 @@ function removeIdle() {

} else {
// The client timed out, call it's destroyer.
// The client timed out, call its destroyer.
log("removeIdle() destroying obj - now:" + now + " timeout:" + timeout);

@@ -190,3 +191,3 @@ me.destroy(availableObjects[i].obj);

}
};
}

@@ -196,7 +197,7 @@ /**

*
* - If there are available clients waiting shift the first one out (LIFO),
* and call it's callback.
* - If there are no waiting clients, try to create one if it wont exciede
* - If there are available clients waiting, shift the first one out (LIFO),
* and call its callback.
* - If there are no waiting clients, try to create one if it won't exceed
* the maximum number of clients.
* - If creating a new client would exciede the maximum, add the client to
* - If creating a new client would exceed the maximum, add the client to
* the wait list.

@@ -249,3 +250,3 @@ */

* Callback function to be called after the acquire is successful.
* The function will recieve the acquired item as the first parameter.
* The function will receive the acquired item as the first parameter.
*

@@ -280,3 +281,3 @@ * @param {Number} priority

me.release = function (obj) {
// check to see if this object has already been release (i.e., is back in the pool of availableObjects)
// check to see if this object has already been released (i.e., is back in the pool of availableObjects)
if (availableObjects.some(function(objWithTimeout) { return (objWithTimeout.obj === obj); })) {

@@ -341,3 +342,3 @@ log("release called twice for the same resource: " + (new Error().stack));

var obj = willDie.shift();
while (obj != null) {
while (obj !== null && obj !== undefined) {
me.destroy(obj.obj);

@@ -349,5 +350,17 @@ obj = willDie.shift();

}
}
};
me.getPoolSize = function() {
return count;
};
me.availableObjectsCount = function() {
return availableObjects.length;
};
me.waitingClientsCount = function() {
return waitingClients.size();
};
return me;
};
{
"name": "generic-pool",
"description": "Generic resource pooling for Node.JS",
"version": "1.0.7",
"version": "1.0.8",
"author": "James Cooper <james@bitmechanic.com>",

@@ -6,0 +6,0 @@ "contributors": [

@@ -13,2 +13,5 @@

1.0.8 - Nov 16 2011
- Merged #21 (add getter methods to see pool size, etc. - contributed by BryanDonovan)
1.0.7 - Oct 17 2011

@@ -15,0 +18,0 @@ - Merged #19 (prevent release on the same obj twice - contributed by tkrynski)

@@ -196,4 +196,89 @@ var assert = require('assert');

});
},
'getPoolSize' : function (beforeExit) {
var assertion_count = 0;
var pool = poolModule.Pool({
name : 'test1',
create : function(callback) { callback({id: Math.floor(Math.random()*1000)}); },
destroy : function(client) { },
max : 2,
idleTimeoutMillis : 100
});
assert.equal(pool.getPoolSize(), 0);
assertion_count += 1;
pool.acquire(function(err, obj1) {
if (err) { throw err; }
assert.equal(pool.getPoolSize(), 1);
assertion_count += 1;
pool.acquire(function(err, obj2) {
if (err) { throw err; }
assert.equal(pool.getPoolSize(), 2);
assertion_count += 1;
pool.release(obj1);
pool.release(obj2);
pool.acquire(function(err, obj3) {
if (err) { throw err; }
// should still be 2
assert.equal(pool.getPoolSize(), 2);
assertion_count += 1;
pool.release(obj3);
});
});
});
beforeExit(function() {
assert.equal(assertion_count, 4);
});
},
'availableObjectsCount' : function (beforeExit) {
var assertion_count = 0;
var pool = poolModule.Pool({
name : 'test1',
create : function(callback) { callback({id: Math.floor(Math.random()*1000)}); },
destroy : function(client) { },
max : 2,
idleTimeoutMillis : 100
});
assert.equal(pool.availableObjectsCount(), 0);
assertion_count += 1;
pool.acquire(function(err, obj1) {
if (err) { throw err; }
assert.equal(pool.availableObjectsCount(), 0);
assertion_count += 1;
pool.acquire(function(err, obj2) {
if (err) { throw err; }
assert.equal(pool.availableObjectsCount(), 0);
assertion_count += 1;
pool.release(obj1);
assert.equal(pool.availableObjectsCount(), 1);
assertion_count += 1;
pool.release(obj2);
assert.equal(pool.availableObjectsCount(), 2);
assertion_count += 1;
pool.acquire(function(err, obj3) {
if (err) { throw err; }
assert.equal(pool.availableObjectsCount(), 1);
assertion_count += 1;
pool.release(obj3);
assert.equal(pool.availableObjectsCount(), 2);
assertion_count += 1;
});
});
});
beforeExit(function() {
assert.equal(assertion_count, 7);
});
}
};
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