From 4aab7631e76fce5ad1c38a7d3af7563cb6c4ad4b Mon Sep 17 00:00:00 2001 From: salacode <55163257+salacode@users.noreply.github.com> Date: Tue, 10 Sep 2019 17:48:27 -0400 Subject: [PATCH 1/4] Adds callback for send(). --- lib/frame.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/frame.js b/lib/frame.js index 65f0fd5..a5d5706 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -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'; @@ -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) { From 6fd35d16841c5ef6c479c4a1daae844171f0698c Mon Sep 17 00:00:00 2001 From: salacode <55163257+salacode@users.noreply.github.com> Date: Tue, 10 Sep 2019 17:52:55 -0400 Subject: [PATCH 2/4] Add callback to publish(). --- lib/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index c6b851f..c33f572 100644 --- a/lib/client.js +++ b/lib/client.js @@ -304,14 +304,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; }; From 2906fc6649b25d26948f92d004bdbe251ba423a4 Mon Sep 17 00:00:00 2001 From: salacode <55163257+salacode@users.noreply.github.com> Date: Tue, 10 Sep 2019 17:55:30 -0400 Subject: [PATCH 3/4] Fixes bug: connection terminates before sending DISCONNECT is completed. --- lib/client.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index c33f572..c08ec44 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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(); }); } From 793d94b3e868bb4ef3635c715e1d1452c5a28b21 Mon Sep 17 00:00:00 2001 From: salacode <55163257+salacode@users.noreply.github.com> Date: Tue, 10 Sep 2019 23:56:21 -0400 Subject: [PATCH 4/4] Updates test, support the new callback functionality of send() --- test/client.test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/client.test.js b/test/client.test.js index ffa5369..49b0f7b 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -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); }); }; @@ -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