@ -855,22 +855,23 @@ define([
} ;
Kernel . prototype . _handle _ws _message = function ( e ) {
var that = this ;
this . _msg _queue = this . _msg _queue . then ( function ( ) {
return serialize . deserialize ( e . data ) ;
} ) . then ( $ . proxy ( this . _finish _ws _message , this ) )
} ) . then ( function ( msg ) { return that . _finish _ws _message ( msg ) ; } )
. catch ( utils . reject ( "Couldn't process kernel message" , true ) ) ;
} ;
Kernel . prototype . _finish _ws _message = function ( msg ) {
switch ( msg . channel ) {
case 'shell' :
this. _handle _shell _reply ( msg ) ;
return this. _handle _shell _reply ( msg ) ;
break ;
case 'iopub' :
this. _handle _iopub _message ( msg ) ;
return this. _handle _iopub _message ( msg ) ;
break ;
case 'stdin' :
this. _handle _input _request ( msg ) ;
return this. _handle _input _request ( msg ) ;
break ;
default :
console . error ( "unrecognized message channel" , msg . channel , msg ) ;
@ -879,10 +880,12 @@ define([
Kernel . prototype . _handle _shell _reply = function ( reply ) {
this . events . trigger ( 'shell_reply.Kernel' , { kernel : this , reply : reply } ) ;
var that = this ;
var content = reply . content ;
var metadata = reply . metadata ;
var parent _id = reply . parent _header . msg _id ;
var callbacks = this . get _callbacks _for _msg ( parent _id ) ;
var promise = Promise . resolve ( ) ;
if ( ! callbacks || ! callbacks . shell ) {
return ;
}
@ -892,17 +895,21 @@ define([
this . _finish _shell ( parent _id ) ;
if ( shell _callbacks . reply !== undefined ) {
shell_callbacks . reply ( reply ) ;
promise = promise . then ( function ( ) { return shell_callbacks . reply ( reply ) } ) ;
}
if ( content . payload && shell _callbacks . payload ) {
this . _handle _payloads ( content . payload , shell _callbacks . payload , reply ) ;
promise = promise . then ( function ( ) {
return that . _handle _payloads ( content . payload , shell _callbacks . payload , reply ) ;
} ) ;
}
return promise ;
} ;
/ * *
* @ function _handle _payloads
* /
Kernel . prototype . _handle _payloads = function ( payloads , payload _callbacks , msg ) {
var promise = [ ] ;
var l = payloads . length ;
// Payloads are handled by triggering events because we don't want the Kernel
// to depend on the Notebook or Pager classes.
@ -910,9 +917,10 @@ define([
var payload = payloads [ i ] ;
var callback = payload _callbacks [ payload . source ] ;
if ( callback ) {
callback( payload , msg ) ;
promise. push ( callback( payload , msg ) ) ;
}
}
return Promise . all ( promise ) ;
} ;
/ * *
@ -1025,7 +1033,7 @@ define([
Kernel . prototype . _handle _iopub _message = function ( msg ) {
var handler = this . get _iopub _handler ( msg . header . msg _type ) ;
if ( handler !== undefined ) {
handler ( msg ) ;
return handler ( msg ) ;
}
} ;