dop251 / goja_nodejs

Nodejs compatibility library for Goja
MIT License
329 stars 78 forks source link

No way to interrupt a script running EventLoop #50

Open zllovesuki opened 1 year ago

zllovesuki commented 1 year ago

It doesn't seem like the Go code can interrupt a running job. The example in https://github.com/dop251/goja#interrupting cannot be replicated when a script is in an infinite loop inside of EventLoop.

dop251 commented 1 year ago

Could you please provide a testcase?

zllovesuki commented 1 year ago

I was thinking that since *goja.Runtime is only available in RunOnLoop(), there's no way to invoke .Interrupt. However it seems that I can keep the reference of Runtime and call Interrupt outside of RunOnLoop.

I will close this issue as it is user error.

dop251 commented 1 year ago

I see. Perhaps it's worth adding loop.Interrupt() which will do a combination of StopNoWait and vm.Interrupt.