mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-10 18:40:27 +00:00
fix(engine): allow JS resource cleanup after interrupting execution
This commit is contained in:
1 parent
1bc31774cb
commit
7cf53240c2
1 file changed
+9
@@ -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
|
||||
|
||||
Reference in new issue
Block a user