Skip to content

Commit a7381b8

Browse files
committed
WebRRunner.run_code_blocks: run the blocks one at a time
The CodeSession is supposed to queue blocks of code, but not doing this led to a very weird error in WebR to do with the session's environment object.
1 parent c32eaa7 commit a7381b8

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

programming.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -775,22 +775,26 @@ Numbas.addExtension('programming', ['display', 'util', 'jme'], function(programm
775775
*/
776776
async run_code_blocks(codes, context_id) {
777777
const session = await this.new_session(context_id);
778-
const results = await Promise.all(codes.map(async (code) => {
779-
if(code.trim()=='') {
780-
return {
781-
result: undefined,
782-
success: true,
783-
stdout: '',
784-
stderr: ''
778+
const results = [];
779+
for(let code of codes) {
780+
const result = await (async function() {
781+
if(code.trim()=='') {
782+
return {
783+
result: undefined,
784+
success: true,
785+
stdout: '',
786+
stderr: ''
787+
}
785788
}
786-
}
787-
try {
788-
const result = await session.run_code(code);
789-
return result;
790-
} catch(error) {
791-
return error;
792-
}
793-
}));
789+
try {
790+
const result = await session.run_code(code);
791+
return result;
792+
} catch(error) {
793+
return error;
794+
}
795+
})();
796+
results.push(result);
797+
}
794798
const webR = await this.load_webR();
795799
const shelter = await session.shelter;
796800
await shelter.purge();

0 commit comments

Comments
 (0)