Can i stop the execution of Blockly using JSInterpreter?

415 views
Skip to first unread message

whaletalent

unread,
Jan 11, 2018, 1:06:40 PM1/11/18
to Blockly
Hello! I wonder if I can create a function that cancels Blockly's step-by-step execution. I'm using JS Interpreter to run custom blocks and it's working perfectly, however, on very long runs, I'd like to cancel execution if possible. How I do a function to cancel the stepInterpreter?

Erik Pasternak

unread,
Jan 11, 2018, 3:20:35 PM1/11/18
to Blockly
Neil may follow up with another suggestion, but we recommending throwing for infinite loops to break out of execution.

Cheers,
Erik

Neil Fraser

unread,
Jan 11, 2018, 3:21:01 PM1/11/18
to blo...@googlegroups.com
I'll assume that you have the following code or something like it somewhere in your program:
function nextStep() {
 
if (myInterpreter.step()) {
    window
.setTimeout(nextStep, 10);
 
}
}
Just keep a record of the timeout's process ID:
var pid = 0;
function nextStep() {
 
if (myInterpreter.step()) {
    pid = window
.setTimeout(nextStep, 10);
 
}
}
Then whenever you want to terminate the execution, call:

window.clearTimeout(pid);

On 11 January 2018 at 10:06, whaletalent <lua...@gmail.com> wrote:
Hello! I wonder if I can create a function that cancels Blockly's step-by-step execution. I'm using JS Interpreter to run custom blocks and it's working perfectly, however, on very long runs, I'd like to cancel execution if possible. How I do a function to cancel the stepInterpreter?

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

whaletalent

unread,
Jan 11, 2018, 9:02:04 PM1/11/18
to Blockly
TY for help guys! And a special thank you again for Neil, my savior! I've tried everything, except use clearTimeout() function. Sorry for this silly question, you helped me a lot!

Reply all
Reply to author
Forward
0 new messages