You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran across what I consider to be a surprising behavior, especially after carefully reading the documentation for Interrupt and ClearInterrupt:
funcTestInterruptRunTwice(t*testing.T) {
constSCRIPT=` var i = 0; for (;;) { i++; } `vm:=New()
time.AfterFunc(200*time.Millisecond, func() {
vm.Interrupt("halt")
})
_, err:=vm.RunString(SCRIPT)
iferr==nil {
t.Fatal("Err is nil")
}
// this will block forever, because the VM uninterrupted itself at the end of the last run_, err=vm.RunString(SCRIPT)
iferr==nil {
t.Fatal("Err is nil")
}
}
My expectation was that the VM would remain interrupted until ClearInterrupt is called.
My understanding is that this surprising behavior may have come to be after the changes in #405, but at the very least it should be documented in the Interrupt and RunScript/RunString/RunProgram functions.
If this is the intended behavior, this begs the question of how to best ensure that a runtime remains stopped (returning *InterruptedError, etc.) even if there are requests to run something[1]. Is the most straightforward solution to add extra logic that always checks if Interrupt needs to be called again after each RunScript/RunString/RunProgram invocation?
[1] Requests which may have been, for example, enqueued via the RunOnLoop function of the goja_nodejs event loop, prior to the loop being Terminated, and which I may want to return immediately with an error due to the runtime having been interrupted after a timeout waiting for the remaining enqueued jobs to complete...
The text was updated successfully, but these errors were encountered:
gbl08ma
added a commit
to tnyim/jungletv
that referenced
this issue
Jul 27, 2024
Interrupt meant to be a one-off event. You should have a state associated with a Runtime that would contain a flag saying it should not be used anymore. If it's not stated clear enough in the docs, please raise a PR.
I ran across what I consider to be a surprising behavior, especially after carefully reading the documentation for
Interrupt
andClearInterrupt
:My expectation was that the VM would remain interrupted until
ClearInterrupt
is called.My understanding is that this surprising behavior may have come to be after the changes in #405, but at the very least it should be documented in the
Interrupt
andRunScript/RunString/RunProgram
functions.If this is the intended behavior, this begs the question of how to best ensure that a runtime remains stopped (returning
*InterruptedError
, etc.) even if there are requests to run something[1]. Is the most straightforward solution to add extra logic that always checks ifInterrupt
needs to be called again after eachRunScript/RunString/RunProgram
invocation?[1] Requests which may have been, for example, enqueued via the
RunOnLoop
function of the goja_nodejs event loop, prior to the loop beingTerminate
d, and which I may want to return immediately with an error due to the runtime having been interrupted after a timeout waiting for the remaining enqueued jobs to complete...The text was updated successfully, but these errors were encountered: