Skip to content
Open
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
16 changes: 12 additions & 4 deletions lib/cradle.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,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();
});
}
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();
});
};

//
// Connection.request()
Expand Down
3 changes: 3 additions & 0 deletions test/connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down