##// END OF EJS Templates
Promise logic is infectious like a disease
Jonathan Frederic -
Show More
@@ -51,7 +51,7 b' define(['
51
51
52 CommManager.prototype.register_comm = function (comm) {
52 CommManager.prototype.register_comm = function (comm) {
53 // Register a comm in the mapping
53 // Register a comm in the mapping
54 this.comms[comm.comm_id] = comm;
54 this.comms[comm.comm_id] = new Promise(function(resolve) {resolve(comm);});
55 comm.kernel = this.kernel;
55 comm.kernel = this.kernel;
56 return comm.comm_id;
56 return comm.comm_id;
57 };
57 };
@@ -66,12 +66,13 b' define(['
66 CommManager.prototype.comm_open = function (msg) {
66 CommManager.prototype.comm_open = function (msg) {
67 var content = msg.content;
67 var content = msg.content;
68 var that = this;
68 var that = this;
69
69 var comm_id = content.comm_id;
70 return utils.load_class(content.target_name, content.target_module,
70
71 this.comms[comm_id] = utils.load_class(content.target_name, content.target_module,
71 this.targets).then(function(target) {
72 this.targets).then(function(target) {
72
73
73 var comm = new Comm(content.target_name, content.comm_id);
74 var comm = new Comm(content.target_name, comm_id);
74 that.register_comm(comm);
75 comm.kernel = that.kernel;
75 try {
76 try {
76 target(comm, msg);
77 target(comm, msg);
77 } catch (e) {
78 } catch (e) {
@@ -83,33 +84,40 b' define(['
83 }
84 }
84 return comm;
85 return comm;
85 }, utils.reject('Could not open comm', true));
86 }, utils.reject('Could not open comm', true));
87 return this.comms[comm_id];
86 };
88 };
87
89
88 CommManager.prototype.comm_close = function (msg) {
90 CommManager.prototype.comm_close = function(msg) {
89 var content = msg.content;
91 var content = msg.content;
90 var comm = this.comms[content.comm_id];
92 if (!this.comms[content.comm_id]) {
91 if (comm === undefined) {
93 console.error('Comm promise not found for comm id ' + content.comm_id);
92 return;
94 return;
93 }
95 }
94 this.unregister_comm(comm);
96
95 try {
97 this.comms[content.comm_id].then(function(comm) {
96 comm.handle_close(msg);
98 this.unregister_comm(comm);
97 } catch (e) {
99 try {
98 console.log("Exception closing comm: ", e, e.stack, msg);
100 comm.handle_close(msg);
99 }
101 } catch (e) {
102 console.log("Exception closing comm: ", e, e.stack, msg);
103 }
104 });
100 };
105 };
101
106
102 CommManager.prototype.comm_msg = function (msg) {
107 CommManager.prototype.comm_msg = function(msg) {
103 var content = msg.content;
108 var content = msg.content;
104 var comm = this.comms[content.comm_id];
109 if (!this.comms[content.comm_id]) {
105 if (comm === undefined) {
110 console.error('Comm promise not found for comm id ' + content.comm_id);
106 return;
111 return;
107 }
112 }
108 try {
113
109 comm.handle_msg(msg);
114 this.comms[content.comm_id].then(function(comm) {
110 } catch (e) {
115 try {
111 console.log("Exception handling comm msg: ", e, e.stack, msg);
116 comm.handle_msg(msg);
112 }
117 } catch (e) {
118 console.log("Exception handling comm msg: ", e, e.stack, msg);
119 }
120 });
113 };
121 };
114
122
115 //-----------------------------------------------------------------------
123 //-----------------------------------------------------------------------
@@ -182,8 +190,9 b' define(['
182
190
183 Comm.prototype.handle_msg = function (msg) {
191 Comm.prototype.handle_msg = function (msg) {
184 var that = this;
192 var that = this;
185 this.msg_promise.then(function() {
193 this.msg_promise = this.msg_promise.then(function() {
186 that._maybe_callback('msg', msg);
194 that._maybe_callback('msg', msg);
195 return Promise.resolve();
187 });
196 });
188 };
197 };
189
198
@@ -26,9 +26,7 b' casper.notebook_test(function () {'
26 'Widget float textbox exists.');
26 'Widget float textbox exists.');
27
27
28 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
28 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
29 console.log('send keys');
30 this.sendKeys(float_text.query, '1.05');
29 this.sendKeys(float_text.query, '1.05');
31 console.log('send keys done');
32 });
30 });
33
31
34 this.wait_for_widget(float_text);
32 this.wait_for_widget(float_text);
General Comments 0
You need to be logged in to leave comments. Login now