diff --git a/IPython/html/static/services/kernels/comm.js b/IPython/html/static/services/kernels/comm.js index 42fe272..0f5363a 100644 --- a/IPython/html/static/services/kernels/comm.js +++ b/IPython/html/static/services/kernels/comm.js @@ -70,23 +70,21 @@ define([ this.comms[comm_id] = utils.load_class(content.target_name, content.target_module, this.targets).then(function(target) { - - var comm = new Comm(content.target_name, comm_id); - comm.kernel = that.kernel; - try { - var response = target(comm, msg); - if (response instanceof Promise) { - return response.then(function() { return Promise.resolve(comm); }); + var comm = new Comm(content.target_name, comm_id); + comm.kernel = that.kernel; + try { + var response = target(comm, msg); + } catch (e) { + comm.close(); + that.unregister_comm(comm); + var wrapped_error = new utils.WrappedError("Exception opening new comm", e); + console.error(wrapped_error); + return Promise.reject(wrapped_error); } - } catch (e) { - comm.close(); - that.unregister_comm(comm); - var wrapped_error = new utils.WrappedError("Exception opening new comm", e); - console.error(wrapped_error); - return Promise.reject(wrapped_error); - } - return Promise.resolve(comm); - }, utils.reject('Could not open comm', true)); + // Regardless of the target return value, we need to + // then return the comm + return Promise.resolve(response).then(function() {return comm;}); + }, utils.reject('Could not open comm', true)); return this.comms[comm_id]; }; @@ -104,6 +102,8 @@ define([ } catch (e) { console.log("Exception closing comm: ", e, e.stack, msg); } + // don't return a comm, so that further .then() functions + // get an undefined comm input }); }; @@ -120,7 +120,7 @@ define([ } catch (e) { console.log("Exception handling comm msg: ", e, e.stack, msg); } - return Promise.resolve(comm); + return comm; }); }; diff --git a/IPython/html/static/widgets/js/manager.js b/IPython/html/static/widgets/js/manager.js index 1507e5f..813b7e3 100644 --- a/IPython/html/static/widgets/js/manager.js +++ b/IPython/html/static/widgets/js/manager.js @@ -49,24 +49,24 @@ define([ WidgetManager.prototype.display_view = function(msg, model) { // Displays a view for a particular model. var that = this; - return new Promise(function(resolve, reject) { - var cell = that.get_msg_cell(msg.parent_header.msg_id); - if (cell === null) { - reject(new Error("Could not determine where the display" + - " message was from. Widget will not be displayed")); - } else if (cell.widget_subarea) { - var dummy = $('
'); - cell.widget_subarea.append(dummy); - that.create_view(model, {cell: cell}).then(function(view) { + var cell = this.get_msg_cell(msg.parent_header.msg_id); + if (cell === null) { + return Promise.reject(new Error("Could not determine where the display" + + " message was from. Widget will not be displayed")); + } else if (cell.widget_subarea) { + var dummy = $(''); + cell.widget_subarea.append(dummy); + return this.create_view(model, {cell: cell}).then( + function(view) { that._handle_display_view(view); dummy.replaceWith(view.$el); view.trigger('displayed'); - resolve(view); - }, function(error) { - reject(new utils.WrappedError('Could not display view', error)); + return view; + }, + function(error) { + return Promise.reject(new utils.WrappedError('Could not display view', error)); }); - } - }); + } }; WidgetManager.prototype._handle_display_view = function (view) { diff --git a/IPython/html/static/widgets/js/widget.js b/IPython/html/static/widgets/js/widget.js index 00a4ca7..06d3827 100644 --- a/IPython/html/static/widgets/js/widget.js +++ b/IPython/html/static/widgets/js/widget.js @@ -95,7 +95,6 @@ define(["widgets/js/manager", } finally { that.state_lock = null; } - return Promise.resolve(); }, utils.reject("Couldn't set model state", true)); },