generic-pool
Advanced tools
@@ -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" | ||
| } |
+7
-1
@@ -23,2 +23,6 @@ [](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 <james@bitmechanic.com> | ||
| Copyright (c) 2010-2014 James Cooper <james@bitmechanic.com> | ||
@@ -329,0 +335,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
-73
| 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(); | ||
| } | ||
| }); | ||
| } |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
350
1.74%49618
-1.59%8
-11.11%991
-4.44%1
Infinity%