##// END OF EJS Templates
Handle kernel messages synchronously...
Jason Grout -
Show More
@@ -117,6 +117,7 b' define(['
117 117 // don't return a comm, so that further .then() functions
118 118 // get an undefined comm input
119 119 });
120 return this.comms[content.comm_id];
120 121 };
121 122
122 123 CommManager.prototype.comm_msg = function(msg) {
@@ -134,6 +135,7 b' define(['
134 135 }
135 136 return comm;
136 137 });
138 return this.comms[content.comm_id];
137 139 };
138 140
139 141 //-----------------------------------------------------------------------
@@ -855,22 +855,23 b' define(['
855 855 };
856 856
857 857 Kernel.prototype._handle_ws_message = function (e) {
858 var that = this;
858 859 this._msg_queue = this._msg_queue.then(function() {
859 860 return serialize.deserialize(e.data);
860 }).then($.proxy(this._finish_ws_message, this))
861 }).then(function(msg) {return that._finish_ws_message(msg);})
861 862 .catch(utils.reject("Couldn't process kernel message", true));
862 863 };
863 864
864 865 Kernel.prototype._finish_ws_message = function (msg) {
865 866 switch (msg.channel) {
866 867 case 'shell':
867 this._handle_shell_reply(msg);
868 return this._handle_shell_reply(msg);
868 869 break;
869 870 case 'iopub':
870 this._handle_iopub_message(msg);
871 return this._handle_iopub_message(msg);
871 872 break;
872 873 case 'stdin':
873 this._handle_input_request(msg);
874 return this._handle_input_request(msg);
874 875 break;
875 876 default:
876 877 console.error("unrecognized message channel", msg.channel, msg);
@@ -879,10 +880,12 b' define(['
879 880
880 881 Kernel.prototype._handle_shell_reply = function (reply) {
881 882 this.events.trigger('shell_reply.Kernel', {kernel: this, reply:reply});
883 var that = this;
882 884 var content = reply.content;
883 885 var metadata = reply.metadata;
884 886 var parent_id = reply.parent_header.msg_id;
885 887 var callbacks = this.get_callbacks_for_msg(parent_id);
888 var promise = Promise.resolve();
886 889 if (!callbacks || !callbacks.shell) {
887 890 return;
888 891 }
@@ -892,17 +895,21 b' define(['
892 895 this._finish_shell(parent_id);
893 896
894 897 if (shell_callbacks.reply !== undefined) {
895 shell_callbacks.reply(reply);
898 promise = promise.then(function() {return shell_callbacks.reply(reply)});
896 899 }
897 900 if (content.payload && shell_callbacks.payload) {
898 this._handle_payloads(content.payload, shell_callbacks.payload, reply);
901 promise = promise.then(function() {
902 return that._handle_payloads(content.payload, shell_callbacks.payload, reply);
903 });
899 904 }
905 return promise;
900 906 };
901 907
902 908 /**
903 909 * @function _handle_payloads
904 910 */
905 911 Kernel.prototype._handle_payloads = function (payloads, payload_callbacks, msg) {
912 var promise = [];
906 913 var l = payloads.length;
907 914 // Payloads are handled by triggering events because we don't want the Kernel
908 915 // to depend on the Notebook or Pager classes.
@@ -910,9 +917,10 b' define(['
910 917 var payload = payloads[i];
911 918 var callback = payload_callbacks[payload.source];
912 919 if (callback) {
913 callback(payload, msg);
920 promise.push(callback(payload, msg));
914 921 }
915 922 }
923 return Promise.all(promise);
916 924 };
917 925
918 926 /**
@@ -1025,7 +1033,7 b' define(['
1025 1033 Kernel.prototype._handle_iopub_message = function (msg) {
1026 1034 var handler = this.get_iopub_handler(msg.header.msg_type);
1027 1035 if (handler !== undefined) {
1028 handler(msg);
1036 return handler(msg);
1029 1037 }
1030 1038 };
1031 1039
General Comments 0
You need to be logged in to leave comments. Login now