File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,16 @@ export default function(RED) {
242242 obj . object . on ( 'data' , func ) ;
243243 return true ;
244244 } ,
245+ unsubscribe : ( ) => {
246+ return new Promise ( ( resolve ) => {
247+ if ( obj . notifiable ) {
248+ delete obj . dataListener ;
249+ obj . object . unsubscribe ( resolve ) ;
250+ } else {
251+ return resolve ( ) ;
252+ }
253+ } ) ;
254+ } ,
245255 } ;
246256 return obj ;
247257 }
@@ -329,6 +339,9 @@ export default function(RED) {
329339 return Promise . resolve ( peripheral . state ) ;
330340 }
331341 } ,
342+ shutdown : ( ) => {
343+ return Promise . all ( this . characteristics . map ( ( c ) => c . unsubscribe ( ) ) ) ;
344+ } ,
332345 register : ( node ) => {
333346 this . nodes [ node . id ] = node ;
334347 } ,
@@ -519,8 +532,9 @@ export default function(RED) {
519532 }
520533 } ) ;
521534 } ) ;
522- this . on ( 'close' , ( ) => {
535+ this . on ( 'close' , ( done ) => {
523536 Object . keys ( configBleDevices ) . forEach ( k => delete configBleDevices [ k ] ) ;
537+ this . operations . shutdown ( ) . then ( done ) . catch ( done ) ;
524538 } ) ;
525539 }
526540 }
You can’t perform that action at this time.
0 commit comments