From a410aa91da54ee4d9d6acd91cae48828c743572f Mon Sep 17 00:00:00 2001 From: Rowan Wookey Date: Sat, 18 Jan 2014 15:47:14 +0000 Subject: [PATCH 1/2] Emit queue event When a connection pool has to queue a connection then emit a queue event with the number of connections in the queue as the first argument --- lib/Pool.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Pool.js b/lib/Pool.js index f751f95d7..3c32ec018 100644 --- a/lib/Pool.js +++ b/lib/Pool.js @@ -64,9 +64,11 @@ Pool.prototype.getConnection = function (cb) { return cb(new Error('Queue limit reached.')); } - if (cb && process.domain) + if (cb && process.domain) { cb = process.domain.bind(cb); + } this._connectionQueue.push(cb); + this.emit('queue',this._connectionQueue.length); }; Pool.prototype.releaseConnection = function (connection) { From 6d9404793d6db81c9ff36e2f2179bf50019a959c Mon Sep 17 00:00:00 2001 From: Rowan Date: Mon, 20 Jan 2014 13:55:16 +0000 Subject: [PATCH 2/2] Updated Readme.md to include queue event --- Readme.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Readme.md b/Readme.md index 9e026d494..9a6afd53c 100644 --- a/Readme.md +++ b/Readme.md @@ -257,6 +257,24 @@ up to 100 connections, but only ever use 5 simultaneously, only 5 connections will be made. Connections are also cycled round-robin style, with connections being taken from the top of the pool and returning to the bottom. +Once the number of active connections reaches `connectionLimit` (see blelow) +the connection will be queued and the pool will emit a `queue` event with +the number of queued connections as the first argument to the callback. + +```js +var mysql = require('mysql'); +var pool = mysql.createPool(...); + +pool.on('queue',function(queuedConnections) { + // Do something i.e. log to console + console.error('connectionLimit reached, '+queuedConnections+' connections in the queue'); +}); + +// Create and use more than connectionLimit connections + +``` + + ## Pool options Pools accept all the same options as a connection. When creating a new