From d31eb502d1fb74425e88f3219f1fcf1d05a36032 Mon Sep 17 00:00:00 2001 From: David Halls Date: Thu, 24 Apr 2014 21:08:33 +0100 Subject: [PATCH 1/3] Fix Connection.close on 0.10 --- lib/cradle.js | 16 ++++++++++++---- test/connection-test.js | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/cradle.js b/lib/cradle.js index b21d5ef..200d9cb 100644 --- a/lib/cradle.js +++ b/lib/cradle.js @@ -161,10 +161,18 @@ cradle.Connection.prototype.rawRequest = function (options, callback) { // Close all underlying sockets associated with the agent for the connection. // cradle.Connection.prototype.close = function () { - this.agent.sockets.forEach(function (socket) { - socket.end(); - }); -} + if (this.agent.sockets.forEach) { + this.agent.sockets.forEach(function (socket) { + socket.end(); + }); + } else { + for (var addr in this.agent.sockets) { + this.agent.sockets[addr].forEach(function (socket) { + socket.end(); + }); + } + } +}; // // Connection.request() diff --git a/test/connection-test.js b/test/connection-test.js index b12c543..5c0ebbc 100644 --- a/test/connection-test.js +++ b/test/connection-test.js @@ -25,6 +25,9 @@ vows.describe('cradle/connection').addBatch({ assert.equal(c.options.milk, 'white'); assert.equal(c.options.cache, true); }, + "should be able to close the Connection": function (c) { + c.close(); + }, "with just a {} passed to a new Connection object": { topic: function () { return new(cradle.Connection)({milk: 'green'}) }, "should override the defaults": function (c) { From 744211b5c72f08e80d6ff5e54960613235df737c Mon Sep 17 00:00:00 2001 From: David Halls Date: Sat, 26 Jul 2014 22:49:09 +0100 Subject: [PATCH 2/3] Use a single array when closing --- lib/cradle.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/cradle.js b/lib/cradle.js index 200d9cb..8ac36f4 100644 --- a/lib/cradle.js +++ b/lib/cradle.js @@ -161,17 +161,17 @@ cradle.Connection.prototype.rawRequest = function (options, callback) { // Close all underlying sockets associated with the agent for the connection. // cradle.Connection.prototype.close = function () { - if (this.agent.sockets.forEach) { - this.agent.sockets.forEach(function (socket) { - socket.end(); - }); - } else { - for (var addr in this.agent.sockets) { - this.agent.sockets[addr].forEach(function (socket) { - socket.end(); - }); - } - } + var agentSockets = this.agent.sockets, + sockets = agentSockets.forEach ? agentSockets : + Object.keys(agentSockets).map(function (addr) { + return agentSockets[addr] + }).reduce(function (x, y) { + return x.concat(y); + }, []); + + sockets.forEach(function (socket) { + socket.end(); + }); }; // From 23bd107285a463ded399ae63e0c886c5da5ff741 Mon Sep 17 00:00:00 2001 From: David Halls Date: Sat, 26 Jul 2014 22:51:40 +0100 Subject: [PATCH 3/3] Missing semi-colon --- lib/cradle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cradle.js b/lib/cradle.js index 8ac36f4..3be028f 100644 --- a/lib/cradle.js +++ b/lib/cradle.js @@ -164,7 +164,7 @@ cradle.Connection.prototype.close = function () { var agentSockets = this.agent.sockets, sockets = agentSockets.forEach ? agentSockets : Object.keys(agentSockets).map(function (addr) { - return agentSockets[addr] + return agentSockets[addr]; }).reduce(function (x, y) { return x.concat(y); }, []);