Skip to content

Commit

Permalink
Fix behavior of close; let close also wait for messages in the discon…
Browse files Browse the repository at this point in the history
…nected queue
  • Loading branch information
R. Cijvat committed Nov 3, 2015
1 parent 686d897 commit eab3000
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions Tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,16 @@ describe("#Connection", function() {

it("should finish all its queries when closed", function() {
var conn = new MDB();
return conn.connect().then(function() {
var qs = [
conn.query("SELECT 1"),
conn.query("SELECT 2"),
conn.query("SELECT 3")
];
conn.close();
return Q.all(qs);
});
conn.connect();

var qs = [
conn.query("SELECT 1"),
conn.query("SELECT 2"),
conn.query("SELECT 3")
];

conn.close();
return Q.all(qs);
});

it("should fail all queries on destroyed connection", function() {
Expand Down
2 changes: 1 addition & 1 deletion src/mapi-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function MapiConnection(options) {
function _nextMessage() {
if (!_messageQueue.length) {
_msgLoopRunning = false;
if (_closeDeferred) {
if ((!_messageQueueDisconnected || !_messageQueueDisconnected.length) && _closeDeferred) {
self.destroy();
_closeDeferred && _closeDeferred.resolve();
}
Expand Down

0 comments on commit eab3000

Please sign in to comment.