Skip to content

Commit b45a828

Browse files
committed
Add enqueue event to protocol and connection
fixes #381
1 parent 048f2c1 commit b45a828

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

Changes.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This file is a manually maintained list of changes for each release. Feel free
44
to add your changes here when sending pull requests. Also send corrections if
55
you spot any mistakes.
66

7+
## HEAD
8+
9+
* Add `enqueue` event to protocol and connection #381
10+
711
## v2.4.1 (2014-07-17)
812

913
* Fix `pool.query` not invoking callback on connection error #872

lib/Connection.js

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Connection.prototype.connect = function connect(options, callback) {
9494
this._protocol.on('unhandledError', this._handleProtocolError.bind(this));
9595
this._protocol.on('drain', this._handleProtocolDrain.bind(this));
9696
this._protocol.on('end', this._handleProtocolEnd.bind(this));
97+
this._protocol.on('enqueue', this._handleProtocolEnqueue.bind(this));
9798

9899
if (this.config.connectTimeout) {
99100
var handleConnectTimeout = this._handleConnectTimeout.bind(this);
@@ -363,6 +364,10 @@ Connection.prototype._handleProtocolEnd = function(err) {
363364
this.emit('end', err);
364365
};
365366

367+
Connection.prototype._handleProtocolEnqueue = function _handleProtocolEnqueue(sequence) {
368+
this.emit('enqueue', sequence);
369+
};
370+
366371
Connection.prototype._implyConnect = function() {
367372
if (!this._connectCalled) {
368373
this.connect();

lib/protocol/Protocol.js

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Protocol.prototype._enqueue = function(sequence) {
136136
}
137137

138138
this._queue.push(sequence);
139+
this.emit('enqueue', sequence);
139140

140141
var self = this;
141142
sequence
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var connection = common.createConnection({port: common.fakeServerPort});
4+
5+
var server = common.createFakeServer();
6+
7+
server.listen(common.fakeServerPort, function (err) {
8+
assert.ifError(err);
9+
10+
var count = 0;
11+
connection.on('enqueue', function () {
12+
count++;
13+
});
14+
15+
connection.on('drain', function () {
16+
assert.equal(count, 3);
17+
connection.destroy();
18+
server.destroy();
19+
});
20+
21+
connection.query('SELECT 1', assert.ifError);
22+
connection.ping(assert.ifError);
23+
});
24+

0 commit comments

Comments
 (0)