Skip to content

Commit

Permalink
Make callbacks follow the 'error as first argument convention'.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekim committed Oct 7, 2012
1 parent 5c48770 commit 40216c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function ConnectionPool(poolConfig, connectionConfig) {
if (pool.pendingConnectionRequests.length > 0) {
var pendingConnectionRequest = pool.pendingConnectionRequests.shift();

pendingConnectionRequest(connection);
pendingConnectionRequest(undefined, connection);
}
};

Expand All @@ -54,19 +54,19 @@ function ConnectionPool(poolConfig, connectionConfig) {
}

if (connection) {
useConnection(connection);
useConnection(undefined, connection);
} else {
pool.pendingConnectionRequests.push(function (connection) {
useConnection(connection);
pool.pendingConnectionRequests.push(function (err, connection) {
useConnection(err, connection);
connection.emit('connect');
});
}

function useConnection(connection) {
function useConnection(err, connection) {
pool.inUseConnections.push(connection);
pool.stats.connectionsInUse++;

callback(connection);
callback(err, connection);
}
};

Expand Down
16 changes: 10 additions & 6 deletions test/connection-pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ function testPool(poolConfig, numberOfConnectionsToUse, useConnectionFunction, d
}

function requestConnectionAndClose(pool, done) {
pool.requestConnection(function (connection) {
pool.requestConnection(function (err, connection) {
assert.ok(!err);

connection.on('connect', function(err) {
connection.close();
});
Expand All @@ -87,18 +89,20 @@ function requestConnectionAndClose(pool, done) {
}

function requestConnectionSelectAndClose(pool, done) {
pool.requestConnection(function (connection) {
pool.requestConnection(function (err, connection) {
assert.ok(!err);

var request = new Request('select 42', function(err, rowCount) {
assert.strictEqual(rowCount, 1)
connection.close()
assert.strictEqual(rowCount, 1);
connection.close();
});

request.on('row', function(columns) {
assert.strictEqual(columns[0].value, 42)
assert.strictEqual(columns[0].value, 42);
});

connection.on('connect', function(err) {
connection.execSql(request)
connection.execSql(request);
});

connection.on('end', function(err) {
Expand Down

0 comments on commit 40216c0

Please sign in to comment.