Skip to content

Commit

Permalink
Repeatable transactions are now paused if there's no connection and r…
Browse files Browse the repository at this point in the history
…esumed when the connection is re-established.
  • Loading branch information
morkai committed Jul 16, 2013
1 parent 3009747 commit 5d72972
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/Master.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ Master.prototype.onConnectionOpen = function()
this.connected = true;
this.connectionCounter += 1;

this.queueRepeatableTransactions();
this.executeQueuedTransactions();

this.emit('connected', this.connectionCounter);
};

Expand Down Expand Up @@ -563,6 +566,17 @@ Master.prototype.addRepeatableTransaction = function(transaction)
});
};

/**
* @private
*/
Master.prototype.queueRepeatableTransactions = function()
{
for (var i = 0, l = this.repeatableTransactions.length; i < l; ++i)
{
this.transactionQueue.push(this.repeatableTransactions[i]);
}
};

/**
* @private
*/
Expand Down Expand Up @@ -614,7 +628,7 @@ Master.prototype.handleError = function(transaction)
{
this.transactionQueue.unshift(transaction);
}
else if (transaction.isRepeatable())
else if (transaction.isRepeatable() && this.isConnected())
{
this.scheduleExecution(transaction);
}
Expand All @@ -633,7 +647,7 @@ Master.prototype.handleResponse = function(transaction, response)
{
this.transactionQueue.unshift(transaction);
}
else if (transaction.isRepeatable())
else if (transaction.isRepeatable() && this.isConnected())
{
this.scheduleExecution(transaction);
}
Expand Down

0 comments on commit 5d72972

Please sign in to comment.