Skip to content

Commit

Permalink
Make runtime clock stop on (runtime) errors #44
Browse files Browse the repository at this point in the history
  • Loading branch information
longouyang committed Dec 8, 2016
1 parent c1a8ac6 commit 04b06dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions docs/webppl-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42626,10 +42626,8 @@ var CodeEditor = React.createClass({
var runT0, runClockId;

var endJob = function (store, returnValue) {
clearInterval(runClockId);
var renderedReturnValue = renderReturnValue(returnValue);
comp.addResult({ type: 'text', message: renderedReturnValue });
comp.setState({ runTime: (_.now() - runT0) / 1000 + 's' });
cleanup();
};

Expand All @@ -42642,15 +42640,21 @@ var CodeEditor = React.createClass({
}

var cleanup = function () {
// remove completed job
jobsQueue.shift();

// stop the runtime clock
clearInterval(runClockId);
comp.setState({ runTime: (_.now() - runT0) / 1000 + 's',
execution: 'idle' });

// undo global variable changes
global['console'] = nativeConsole;
global['print'] = null;
global['resumeTrampoline'] = null;
global['onerror'] = null;
wpEditor['makeResultContainer'] = null;
comp.setState({ execution: 'idle' });

// remove completed job
jobsQueue.shift();
// if there are remaining jobs, start on the next one
if (jobsQueue.length > 0) {
jobsQueue[0]();
Expand Down
14 changes: 9 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,8 @@ var CodeEditor = React.createClass({
var runT0, runClockId;

var endJob = function(store, returnValue) {
clearInterval(runClockId);
var renderedReturnValue = renderReturnValue(returnValue);
comp.addResult({type: 'text', message: renderedReturnValue });
comp.setState({runTime: (_.now() - runT0)/1000 + 's'});
cleanup();
}

Expand All @@ -310,15 +308,21 @@ var CodeEditor = React.createClass({
}

var cleanup = function() {
// remove completed job
jobsQueue.shift();

// stop the runtime clock
clearInterval(runClockId);
comp.setState({runTime: (_.now() - runT0)/1000 + 's',
execution: 'idle'});

// undo global variable changes
global['console'] = nativeConsole;
global['print'] = null;
global['resumeTrampoline'] = null;
global['onerror'] = null;
wpEditor['makeResultContainer'] = null;
comp.setState({execution: 'idle'});

// remove completed job
jobsQueue.shift();
// if there are remaining jobs, start on the next one
if (jobsQueue.length > 0) {
jobsQueue[0]()
Expand Down

0 comments on commit 04b06dd

Please sign in to comment.