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
8 changes: 3 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ StompClient.prototype.disconnect = function (callback) {

var frame = new StompFrame({
command: 'DISCONNECT'
}).send(this.stream);

process.nextTick(function() {
}).send(this.stream, function() {
self.stream.end();
});
}
Expand Down Expand Up @@ -304,14 +302,14 @@ StompClient.prototype.unsubscribe = function (queue, headers) {
return this;
};

StompClient.prototype.publish = function(queue, message, headers) {
StompClient.prototype.publish = function(queue, message, headers, cb) {
headers = _extend({}, headers);
headers.destination = queue;
new StompFrame({
command: 'SEND',
headers: headers,
body: message
}).send(this.stream);
}).send(this.stream, cb);
return this;
};

Expand Down
4 changes: 2 additions & 2 deletions lib/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ StompFrame.prototype.toString = function() {
});
};

StompFrame.prototype.send = function(stream) {
StompFrame.prototype.send = function(stream, cb) {
// Avoid small writes, they get sent in their own tcp packet, which
// is not efficient (and v8 does fast string concat).
var frame = this.command + '\n';
Expand All @@ -34,7 +34,7 @@ StompFrame.prototype.send = function(stream) {
}
frame += '\0';
if(frame)
stream.write(frame);
stream.write(frame, cb);
};

StompFrame.prototype.setCommand = function(command) {
Expand Down
7 changes: 4 additions & 3 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ module.exports = testCase({
};

oldSend = StompFrame.prototype.send;
StompFrame.prototype.send = function(stream) {
StompFrame.prototype.send = function(stream, cb) {
var self = this;
process.nextTick(function () {
sendHook(self);
sendHook(self, cb);
});
};

Expand Down Expand Up @@ -603,10 +603,11 @@ module.exports = testCase({
self.stompClient.connect(function() {

// Assert next outbound STOMP frame is a DISCONNECT
sendHook = function (stompFrame) {
sendHook = function (stompFrame, cb) {
test.equal(stompFrame.command, 'DISCONNECT');
test.deepEqual(stompFrame.headers, {});
test.equal(stompFrame.body, '');
cb();
};

// Set disconnection callback to ensure it is called appropriately
Expand Down