use promises to wait for kernelspecs on notebook load

should avoid race condition that causes attempt to load kernelspec
prior to loading the kernelspec list
pull/37/head
Min RK 11 years ago
parent 84d6863d2e
commit 1028c8d192

@ -9,6 +9,7 @@ define([
"use strict";
var KernelSelector = function(selector, notebook) {
var that = this;
this.selector = selector;
this.notebook = notebook;
this.notebook.set_kernelselector(this);
@ -22,6 +23,11 @@ define([
this.bind_events();
// Make the object globally available for user convenience & inspection
IPython.kernelselector = this;
this._finish_load = null;
this.loaded = new Promise(function(resolve, reject) {
that._finish_load = resolve;
});
Object.seal(this);
};
@ -67,6 +73,8 @@ define([
.text(ks.spec.display_name));
new_notebook_submenu.append(ks_submenu_entry);
}
// trigger loaded promise
this._finish_load();
};
KernelSelector.prototype._spec_changed = function (event, ks) {

@ -2077,11 +2077,16 @@ define([
* @param {string} notebook_path - A notebook to load
*/
Notebook.prototype.load_notebook = function (notebook_path) {
var that = this;
this.notebook_path = notebook_path;
this.notebook_name = utils.url_path_split(this.notebook_path)[1];
this.events.trigger('notebook_loading.Notebook');
this.contents.get(notebook_path, {type: 'notebook'}).then(
$.proxy(this.load_notebook_success, this),
function (data) {
that.kernel_selector.loaded.then(
that.load_notebook_success(data)
);
},
$.proxy(this.load_notebook_error, this)
);
};

Loading…
Cancel
Save