Skip to content

Emit queue event #716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ fails assumed to be plaintext strings.
The `ssl` option in the connection options takes a string or an object. When given a string,
it uses one of the predefined SSL profiles included. The following profiles are included:

* `"Amazon RDS"`: this profile is for connecting to an Amazon RDS server and contains the
ca from https://rds.amazonaws.com/doc/rds-ssl-ca-cert.pem
* `"Amazon RDS"`: this profile is for connecting to an Amazon RDS server and contains the
ca from https://rds.amazonaws.com/doc/rds-ssl-ca-cert.pem

When connecting to other servers, you will need to provide an object of options, in the
same format as [crypto.createCredentials](http://nodejs.org/api/crypto.html#crypto_crypto_createcredentials_details).
Please note the arguments expect a string of the certificate, not a file name to the
Expand Down Expand Up @@ -319,6 +319,23 @@ 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

```

When a previous connection is retrieved from the pool, a ping packet is sent
to the server to check if the connection is still good.

Expand Down
4 changes: 3 additions & 1 deletion lib/Pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,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.acquireConnection = function acquireConnection(connection, cb) {
Expand Down