Skip to content

Commit

Permalink
🐛 Fix inflight/pending callbacks execute in wrong order
Browse files Browse the repository at this point in the history
  • Loading branch information
benjismith committed Jul 20, 2024
1 parent 161d8b5 commit 13f6418
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/client/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Doc.prototype._handleFetch = function(error, snapshot) {
var callbacks = this.pendingFetch;
this.pendingFetch = [];
var callback = this.inflightFetch.shift();
if (callback) callbacks.push(callback);
if (callback) callbacks.unshift(callback);
if (callbacks.length) {
callback = function(error) {
util.callEach(callbacks, error);
Expand Down
15 changes: 15 additions & 0 deletions test/client/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ describe('Doc', function() {
doc.fetch(finish);
doc.fetch(finish);
});
it('callbacks called in correct order when fetching and applying ops in quick succession', function(done) {
var connection = this.connection;
var doc = connection.get('dogs', 'fido');
doc.create({name: 'fido'});
var order = ""

Check failure on line 108 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

Strings must use singlequote

Check failure on line 108 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

Missing semicolon

Check failure on line 108 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

Strings must use singlequote

Check failure on line 108 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

Missing semicolon
doc.fetch(function() { order += "A" });

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

Statement inside of curly braces should be on next line

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

Unexpected space(s) after '{'

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

This line has 2 statements. Maximum allowed is 1

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

Strings must use singlequote

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

Unexpected space(s) before '}'

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

Missing semicolon

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

Statement inside of curly braces should be on next line

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

Unexpected space(s) after '{'

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

This line has 2 statements. Maximum allowed is 1

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

Strings must use singlequote

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

Unexpected space(s) before '}'

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

Missing semicolon

Check failure on line 109 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
doc.submitOp([{p: ['snacks'], oi: true}]);
doc.fetch(function() { order += "B" });

Check failure on line 111 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 18

Statement inside of curly braces should be on next line

Check failure on line 111 in test/client/doc.js

View workflow job for this annotation

GitHub Actions / Node 20

Statement inside of curly braces should be on next line
doc.submitOp([{p: ['color'], oi: 'gray'}]);
doc.fetch(function() { order += "C" });
doc.whenNothingPending(function() {
expect(order).to.eql("ABC");
done();
});
});
});

describe('when connection closed', function() {
Expand Down

0 comments on commit 13f6418

Please sign in to comment.