File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -295,7 +295,7 @@ Doc.prototype._handleFetch = function(error, snapshot) {
295
295
var callbacks = this . pendingFetch ;
296
296
this . pendingFetch = [ ] ;
297
297
var callback = this . inflightFetch . shift ( ) ;
298
- if ( callback ) callbacks . push ( callback ) ;
298
+ if ( callback ) callbacks . unshift ( callback ) ;
299
299
if ( callbacks . length ) {
300
300
callback = function ( error ) {
301
301
util . callEach ( callbacks , error ) ;
Original file line number Diff line number Diff line change @@ -101,6 +101,27 @@ describe('Doc', function() {
101
101
doc . fetch ( finish ) ;
102
102
doc . fetch ( finish ) ;
103
103
} ) ;
104
+ it ( 'callbacks called in correct order when fetching and applying ops in quick succession' , function ( done ) {
105
+ var connection = this . connection ;
106
+ var doc = connection . get ( 'dogs' , 'fido' ) ;
107
+ doc . create ( { name : 'fido' } ) ;
108
+ var order = '' ;
109
+ doc . fetch ( function ( ) {
110
+ order += 'A' ;
111
+ } ) ;
112
+ doc . submitOp ( [ { p : [ 'snacks' ] , oi : true } ] ) ;
113
+ doc . fetch ( function ( ) {
114
+ order += 'B' ;
115
+ } ) ;
116
+ doc . submitOp ( [ { p : [ 'color' ] , oi : 'gray' } ] ) ;
117
+ doc . fetch ( function ( ) {
118
+ order += 'C' ;
119
+ } ) ;
120
+ doc . whenNothingPending ( function ( ) {
121
+ expect ( order ) . to . eql ( 'ABC' ) ;
122
+ done ( ) ;
123
+ } ) ;
124
+ } ) ;
104
125
} ) ;
105
126
106
127
describe ( 'when connection closed' , function ( ) {
You can’t perform that action at this time.
0 commit comments