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 {
214214 /**
215215 * Close model
216216 *
217+ * @param comm_closed - true if the comm is already being closed. If false, the comm will be closed.
218+ *
217219 * @returns - a promise that is fulfilled when all the associated views have been removed.
218220 */
219- close ( ) : Promise < void > {
221+ close ( comm_closed = false ) : Promise < void > {
220222 // can only be closed once.
221223 if ( this . _closed ) {
222224 return Promise . resolve ( ) ;
223225 }
224226 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+ }
227233 }
228234 this . stopListening ( ) ;
229235 this . trigger ( 'destroy' , this ) ;
@@ -248,10 +254,10 @@ export class WidgetModel extends Backbone.Model {
248254 */
249255 _handle_comm_closed ( msg : KernelMessage . ICommCloseMsg ) : void {
250256 this . comm_live = false ;
251- if ( this . _closed ) {
252- this . close ( ) ;
253- }
254257 this . trigger ( 'comm:close' ) ;
258+ if ( ! this . _closed ) {
259+ this . close ( true ) ;
260+ }
255261 }
256262
257263 /**
You can’t perform that action at this time.
0 commit comments