Fix connection double closing.

This commit is contained in:
Julien Fontanet 2015-02-03 14:33:39 +01:00
parent d2d401883e
commit bc9975baa1
2 changed files with 12 additions and 4 deletions

View File

@ -12,26 +12,34 @@ var assign = require('lodash.assign');
var has = Object.prototype.hasOwnProperty;
has = has.call.bind(has);
function noop() {}
//====================================================================
var Connection = function Connection(opts) {
function Connection(opts) {
EventEmitter.call(this);
this.data = Object.create(null);
this._close = opts.close;
this.notify = opts.notify;
};
}
inherits(Connection, EventEmitter);
assign(Connection.prototype, {
// Close the connection.
close: function () {
// Prevent errors when the connection is closed more than once.
this.close = noop;
this._close();
this.emit('close');
// Releases values AMAP to ease the garbage collecting.
for (var key in this)
{
if (has(this, key))
if (key !== 'close' && has(this, key))
{
delete this[key];
}

View File

@ -158,7 +158,7 @@ exports = module.exports = $coroutine (args) ->
# Close the connection with the socket.
socket.on 'close', ->
$debug '- WebSocket connection'
$bind connection.close, connection
connection.close()
return
# Connect the WebSocket to the JSON-RPC server