mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
hotfix: clear the offline queue when once written
This commit is contained in:
parent
79c2337705
commit
c035eca3c6
@ -74,10 +74,7 @@ var Connection = exports.Connection = function(stream, options) {
|
|||||||
this.framePos = 0;
|
this.framePos = 0;
|
||||||
this.frame = null;
|
this.frame = null;
|
||||||
self.initialize_retry_vars();
|
self.initialize_retry_vars();
|
||||||
|
self.flush_offline_queue();
|
||||||
self.offline_queue.forEach(function(data) {
|
|
||||||
self.connection.write(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.emit("connect");
|
self.emit("connect");
|
||||||
});
|
});
|
||||||
@ -177,6 +174,18 @@ Connection.prototype.initialize_retry_vars = function () {
|
|||||||
this.attempts = 0;
|
this.attempts = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Connection.prototype.flush_offline_queue = function () {
|
||||||
|
var self = this;
|
||||||
|
var offline_queue = this.offline_queue;
|
||||||
|
|
||||||
|
// Reset offline queue
|
||||||
|
this.offline_queue = [];
|
||||||
|
// Attempt to write queued items
|
||||||
|
offline_queue.forEach(function(data) {
|
||||||
|
self.write(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Connection.prototype.write = function(data) {
|
Connection.prototype.write = function(data) {
|
||||||
if (!this.connected) {
|
if (!this.connected) {
|
||||||
this.offline_queue.push(data);
|
this.offline_queue.push(data);
|
||||||
@ -311,10 +320,7 @@ var StdIOConnection = exports.StdIOConnection = function(command, options) {
|
|||||||
this.frame = null;
|
this.frame = null;
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
|
|
||||||
self.offline_queue.forEach(function(data) {
|
self.flush_offline_queue();
|
||||||
self.connection.write(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
this.connection.addListener("error", function(err) {
|
this.connection.addListener("error", function(err) {
|
||||||
self.emit("error", err);
|
self.emit("error", err);
|
||||||
@ -359,6 +365,18 @@ StdIOConnection.prototype.end = function() {
|
|||||||
this.connection.end();
|
this.connection.end();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
StdIOConnection.prototype.flush_offline_queue = function () {
|
||||||
|
var self = this;
|
||||||
|
var offline_queue = this.offline_queue;
|
||||||
|
|
||||||
|
// Reset offline queue
|
||||||
|
this.offline_queue = [];
|
||||||
|
// Attempt to write queued items
|
||||||
|
offline_queue.forEach(function(data) {
|
||||||
|
self.write(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
StdIOConnection.prototype.write = function(data) {
|
StdIOConnection.prototype.write = function(data) {
|
||||||
if (!this.connected) {
|
if (!this.connected) {
|
||||||
this.offline_queue.push(data);
|
this.offline_queue.push(data);
|
||||||
|
Loading…
Reference in New Issue
Block a user