process

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 3 Imported by: 0

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Watcher

func Watcher(handle func())

Watcher 监听系统信号,阻塞当前 goroutine 直到接收到终止信号。 支持的信号: SIGTERM, SIGQUIT, SIGINT handle: 接收到信号后执行的回调函数,通常用于资源清理

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL