shutdown

package
v1.42.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context() context.Context

Context 返回进程级退出 Context。 首次收到系统信号或 Exit 请求时该 Context 会被取消,调用方不得尝试复用已退出的进程状态。

func Exit

func Exit(message string)

Exit 请求应用结束运行。 仅保留首个尚未消费的退出原因;后续重复请求直接返回,避免故障 goroutine 永久阻塞。

func WaitExit

func WaitExit(config *Configuration) string

WaitExit 阻塞等待系统信号或组件主动退出,并返回触发退出的原因。 函数返回前会停止本次 signal.Notify 注册,避免重复调用累积信号订阅资源。

Types

type Configuration

type Configuration struct {
	// BeforeExit 在取消全局 Context 后同步执行,用于记录退出原因等轻量操作。
	BeforeExit func(string)
	// Signals 指定需要监听的系统信号;为空时监听 SIGINT 和 SIGTERM。
	Signals []os.Signal
}

Configuration 定义应用退出信号和收到退出请求后的通知回调。

Jump to

Keyboard shortcuts

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