Interrupt running script #1154
-
im trying to make it possible to stop a script running in its own thread, but i cant find any way to do it while(true) {
try {
sleep(1000)
print("Still running")
} catch(e) {
print(`Catched ${e}`)
}
} i tried exceptions, but the catch block catches any exception or error and i tried closing the scope (with LOTS of reflection because the built-in function closes the context in the thread) but it doesnt seem to do anything (no errors, script keeps running) so im guessing it doesnt do anything to the script |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You may take a look at the continuation API https://github.com/mozilla/rhino/blob/master/testsrc/org/mozilla/javascript/tests/ContinuationsApiTest.java or the debugger API. The debugger can set breakpoints and pause the script. To open the debugger you may use this code snippet import org.mozilla.javascript.tools.debugger.Main;
...
Context cx = Context.enter();
try {
ScopeProvider provider = () -> ScriptRuntime.getTopCallScope(Context.getCurrentContext());
Main main = Main.mainEmbedded(cx.getFactory(), provider, "Debugger");
main.setExitAction(() -> main.detach());
} finally {
Context.exit();
} |
Beta Was this translation helpful? Give feedback.
-
@kotakotik22 from where are you trying to interrupt the script? From inside the script itself of from the outside, in Java code? Are you running in interpreted mode or compiled? Also see #49 and #175 |
Beta Was this translation helpful? Give feedback.
@kotakotik22 from where are you trying to interrupt the script? From inside the script itself of from the outside, in Java code?
Are you running in interpreted mode or compiled? Also see #49 and #175