fix(engine): allow JS resource cleanup after interrupting execution

This commit is contained in:
Levi committed 2026-11-10 09:33:27 +08:00
1 parent 1bc31774cb
commit 7cf53240c2
1 file changed
+9
+9
View File
@@ -174,6 +174,15 @@ func (e *Engine) Close() {
e.closeOnce.Do(func() {
close(e.done)
e.Runtime.Interrupt(ErrClosed)
// Wait for interrupted JS to leave the loop, then allow cleanup hooks
// to execute their JS cancellation callbacks before terminating it.
cleared := make(chan struct{})
if e.loop.RunOnLoop(func(runtime *goja.Runtime) {
runtime.ClearInterrupt()
close(cleared)
}) {
<-cleared
}
e.cleanupMu.Lock()
cleanups := e.cleanups
e.cleanups = nil