Created
October 7, 2011 21:00
-
-
Save w1nk/1271340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Pool = require('../odbc.js').Pool; | |
var pool = new Pool(); | |
var Database = require('../odbc.js').Database; | |
var connectionString = 'DRIVER={pgdb};SERVER=192.168.x.x;UID=postgres;PWD=;DATABASE=postgres'; | |
var connections = []; | |
var connectCount = 100; | |
openConnectionsUsingPool(); | |
function openConnectionsUsingPool() { | |
for (var x = 0; x < connectCount; x++) | |
{ | |
console.log("opening connection #", x); | |
pool.open(connectionString, function(err, connection) | |
{ | |
if(err) | |
throw err; | |
console.log("opened connection #" + connections.length); | |
connections.push(connection); | |
if(connections.length == connectCount) | |
{ | |
process.nextTick(function() { closeConnections(connections); }); | |
} | |
}); | |
} | |
} | |
function closeConnections () { | |
for(var i = 0; i < connections.length; i++) | |
{ | |
console.log("closing connection #", i); | |
var close = function(i) | |
{ | |
connections[i].close(function() | |
{ | |
console.log("closed connection #" + i); | |
if(i == (connectCount-1)) | |
{ | |
connections = []; | |
process.nextTick(function() { openConnectionsUsingPool(); }); | |
} | |
}); | |
}; | |
close(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment