mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
add g.Listen for automatic signal handling feature
This commit is contained in:
@ -19,11 +19,16 @@ func NewVar(i interface{}, safe ...bool) *Var {
|
||||
return gvar.New(i, safe...)
|
||||
}
|
||||
|
||||
// Wait blocks until:
|
||||
// 1. All the web servers shutdown, it does nothing if there's no running web server.
|
||||
// 2. Shutdown signals received and all registered shutdown handlers done.
|
||||
// Wait is an alias of ghttp.Wait, which blocks until all the web servers shutdown.
|
||||
// It's commonly used in multiple servers situation.
|
||||
func Wait() {
|
||||
ghttp.Wait()
|
||||
}
|
||||
|
||||
// Listen is an alias of gproc.Listen, which handles the signals received and automatically
|
||||
// calls registered signal handler functions.
|
||||
// It blocks until shutdown signals received and all registered shutdown handlers done.
|
||||
func Listen() {
|
||||
gproc.Listen()
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
package gproc
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
@ -64,6 +65,7 @@ func Listen() {
|
||||
for {
|
||||
wg := sync.WaitGroup{}
|
||||
sig = <-sigChan
|
||||
intlog.Printf(`signal received: %s`, sig.String())
|
||||
if handlers, ok := signalHandlerMap[sig]; ok {
|
||||
for _, handler := range handlers {
|
||||
wg.Add(1)
|
||||
|
||||
Reference in New Issue
Block a user