package
Version:
v0.3.6
Opens a new window with list of versions in this module.
Published: Jan 15, 2026
License: MIT
Opens a new window with license information.
Imports: 3
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Process (进程)
提供进程信号处理工具,用于实现优雅关闭。
API
Watcher
- 签名:
func Watcher(handle func())
- 描述: 阻塞监听系统信号(SIGTERM, SIGQUIT, SIGINT),在接收到信号时执行回调函数
handle。
示例
import (
"fmt"
"github.com/fireflycore/go-utils/process"
)
func main() {
// 启动服务...
// 阻塞等待退出信号
process.Watcher(func() {
fmt.Println("Cleaning up resources...")
// 执行清理逻辑,如关闭数据库连接
})
fmt.Println("Server exited")
}
Documentation
¶
func Watcher(handle func())
Watcher 监听系统信号,阻塞当前 goroutine 直到接收到终止信号。
支持的信号: SIGTERM, SIGQUIT, SIGINT
handle: 接收到信号后执行的回调函数,通常用于资源清理
Source Files
¶
Click to show internal directories.
Click to hide internal directories.