Skip to content

Commit

Permalink
fix(link): promisify detach, properly send closed flag in frame
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Jun 11, 2015
1 parent 38d6d59 commit 158a221
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/link.js
@@ -1,6 +1,7 @@
'use strict';

var EventEmitter = require('events').EventEmitter,
Promise = require('bluebird'),
util = require('util'),

StateMachine = require('stately.js'),
Expand Down Expand Up @@ -93,8 +94,22 @@ Link.prototype.attach = function() {
};

Link.prototype.detach = function() {
var self = this;
var detachPromise = new Promise(function(resolve, reject) {
self.once(Link.Detached, function(info) {
if (!!info.error) return reject(info.error);
if (!info.closed) return reject('link not closed');
resolve();
});

self.once(Link.ErrorReceived, function(err) {
reject(err);
});
});

this.linkSM.sendDetach();
this._sendDetach();
return detachPromise;
};

Link.prototype.isSender = function() { return this.role === constants.linkRole.sender; };
Expand Down Expand Up @@ -218,6 +233,7 @@ Link.prototype._detachReceived = function(frame) {
Link.prototype._sendDetach = function() {
var detachFrame = new DetachFrame(this.policy.options);
detachFrame.channel = this.session.channel;
detachFrame.closed = true;
this.session.connection.sendFrame(detachFrame);
};

Expand Down

0 comments on commit 158a221

Please sign in to comment.