File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -105,10 +105,15 @@ Doc.prototype.destroy = function(callback) {
105
105
var doc = this ;
106
106
doc . whenNothingPending ( function ( ) {
107
107
if ( doc . wantSubscribe ) {
108
- doc . unsubscribe ( ) ;
108
+ doc . unsubscribe ( function ( err ) {
109
+ if ( ! err ) doc . connection . _destroyDoc ( doc ) ;
110
+ if ( callback ) return callback ( err ) ;
111
+ if ( err ) this . emit ( 'error' , err ) ;
112
+ } ) ;
113
+ } else {
114
+ doc . connection . _destroyDoc ( doc ) ;
115
+ if ( callback ) callback ( ) ;
109
116
}
110
- doc . connection . _destroyDoc ( doc ) ;
111
- if ( callback ) callback ( ) ;
112
117
} ) ;
113
118
} ;
114
119
Original file line number Diff line number Diff line change @@ -414,7 +414,7 @@ describe('client subscribe', function() {
414
414
doc2 . subscribe ( function ( err ) {
415
415
if ( err ) return done ( err ) ;
416
416
doc2 . on ( 'op' , function ( op , context ) {
417
- done ( ) ;
417
+ done ( new Error ( 'Should not get op event' ) ) ;
418
418
} ) ;
419
419
doc2 . destroy ( function ( err ) {
420
420
if ( err ) return done ( err ) ;
@@ -425,6 +425,17 @@ describe('client subscribe', function() {
425
425
} ) ;
426
426
} ) ;
427
427
428
+ it ( 'doc destroy removes doc from connection when doc is not subscribed' , function ( done ) {
429
+ var connection = this . backend . connect ( ) ;
430
+ var doc = connection . get ( 'dogs' , 'fido' ) ;
431
+ expect ( connection . getExisting ( 'dogs' , 'fido' ) ) . equal ( doc ) ;
432
+ doc . destroy ( function ( err ) {
433
+ if ( err ) return done ( err ) ;
434
+ expect ( connection . getExisting ( 'dogs' , 'fido' ) ) . equal ( undefined ) ;
435
+ done ( ) ;
436
+ } ) ;
437
+ } ) ;
438
+
428
439
it ( 'bulk unsubscribe stops op updates' , function ( done ) {
429
440
var connection = this . backend . connect ( ) ;
430
441
var connection2 = this . backend . connect ( ) ;
You can’t perform that action at this time.
0 commit comments