Skip to content

Commit

Permalink
Use simpler wrap logic to maximize range
Browse files Browse the repository at this point in the history
  • Loading branch information
alevy authored Sep 25, 2020
1 parent b5ee4b0 commit e88faf6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/memjs/memjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,13 +798,12 @@ Client.prototype.perform = function(key, request, seq, callback, retries) {

// Increment the seq value
Client.prototype.incrSeq = function() {
// Prevent seq from being larger than 2^31
// so that range errors do not occur. In event
// this occurs we simply roll over the value.
if (this.seq > Math.pow(2,31)) {
// Wrap `this.seq` to 32-bits since the field we fit it into is only 32-bits.
if (this.seq == 0xffffffff) {
this.seq = 0;
} else {
this.seq++;
}
this.seq++;
};

exports.Client = Client;
Expand Down

0 comments on commit e88faf6

Please sign in to comment.