From 40216c0df2b2f5222e71d2bf548061f7f7baf244 Mon Sep 17 00:00:00 2001 From: Mike D Pilsbury Date: Sun, 7 Oct 2012 16:04:36 +0100 Subject: [PATCH] Make callbacks follow the 'error as first argument convention'. --- lib/connection-pool.js | 12 ++++++------ test/connection-pool.test.js | 16 ++++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/connection-pool.js b/lib/connection-pool.js index db2a67e..89f4e85 100644 --- a/lib/connection-pool.js +++ b/lib/connection-pool.js @@ -37,7 +37,7 @@ function ConnectionPool(poolConfig, connectionConfig) { if (pool.pendingConnectionRequests.length > 0) { var pendingConnectionRequest = pool.pendingConnectionRequests.shift(); - pendingConnectionRequest(connection); + pendingConnectionRequest(undefined, connection); } }; @@ -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); } }; diff --git a/test/connection-pool.test.js b/test/connection-pool.test.js index 10c5b0a..df2e03b 100644 --- a/test/connection-pool.test.js +++ b/test/connection-pool.test.js @@ -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(); }); @@ -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) {