File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -214,16 +214,22 @@ export class WidgetModel extends Backbone.Model {
214
214
/**
215
215
* Close model
216
216
*
217
+ * @param comm_closed - true if the comm is already being closed. If false, the comm will be closed.
218
+ *
217
219
* @returns - a promise that is fulfilled when all the associated views have been removed.
218
220
*/
219
- close ( ) : Promise < void > {
221
+ close ( comm_closed = false ) : Promise < void > {
220
222
// can only be closed once.
221
223
if ( this . _closed ) {
222
224
return Promise . resolve ( ) ;
223
225
}
224
226
this . _closed = true ;
225
- if ( this . comm && this . comm_live ) {
226
- this . comm . close ( ) ;
227
+ if ( this . comm && ! comm_closed && this . comm_live ) {
228
+ try {
229
+ this . comm . close ( ) ;
230
+ } catch ( err ) {
231
+ // Do Nothing
232
+ }
227
233
}
228
234
this . stopListening ( ) ;
229
235
this . trigger ( 'destroy' , this ) ;
@@ -248,10 +254,10 @@ export class WidgetModel extends Backbone.Model {
248
254
*/
249
255
_handle_comm_closed ( msg : KernelMessage . ICommCloseMsg ) : void {
250
256
this . comm_live = false ;
251
- if ( this . _closed ) {
252
- this . close ( ) ;
253
- }
254
257
this . trigger ( 'comm:close' ) ;
258
+ if ( ! this . _closed ) {
259
+ this . close ( true ) ;
260
+ }
255
261
}
256
262
257
263
/**
You can’t perform that action at this time.
0 commit comments