fix bug for WaitAll

This commit is contained in:
Star 2025-07-18 22:40:17 +08:00
parent e8219eb1ec
commit 7bae8c77a2

View File

@ -192,12 +192,11 @@ func WaitAll() {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP)
go func() {
for {
select {
case sig := <-sigCh:
for sig := range sigCh {
if stopped {
break
}
stopped = true
// send signal
for _, fn := range onSignals {
fn(sig)
@ -213,7 +212,6 @@ func WaitAll() {
break
}
}
}
}()
// 一些必须在主线程运行的代码在这运行(例如 apigo.cc/gojs/client
for _, fn := range runInMainFuncs {
@ -231,10 +229,13 @@ func WaitAll() {
}(fn)
}
<-waitChan
if !stopped {
// 优雅的关闭信号等待线程
stopped = true
sigCh <- syscall.SIGTERM
}
}
}
func RunFile(file string, args ...any) (any, error) {
if code, err := u.ReadFile(file); err == nil {