Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WaitForAsync ¶ added in v0.1.3
func WaitForAsync(sigs ...*TerminateSignal)
WaitForAsync 函数等待所有的异步关闭信号 The WaitForAsync function waits for all asynchronous shutdown signals
func WaitForForceSync ¶ added in v0.1.3
func WaitForForceSync(sigs ...*TerminateSignal)
WaitForForceSync 函数等待所有的强制同步关闭信号 The WaitForForceSync function waits for all forced synchronous shutdown signals
func WaitForSync ¶ added in v0.1.3
func WaitForSync(sigs ...*TerminateSignal)
WaitForSync 函数等待所有的同步关闭信号 The WaitForSync function waits for all synchronous shutdown signals
func WaitingForGracefulShutdown
deprecated
func WaitingForGracefulShutdown(sigs ...*TerminateSignal)
WaitingForGracefulShutdown 函数等待所有的关闭信号 The WaitingForGracefulShutdown function waits for all shutdown signals
Deprecated: As of GS v0.1.3 this function simply calls WaitForAsync.
Types ¶
type CloseType ¶ added in v0.1.3
type CloseType int8
CloseType 是一个 int8 类型的别名,用于表示关闭类型 CloseType is an alias for int8, used to represent the type of closure
const ( // ASyncClose 表示异步关闭,即在新的 goroutine 中执行关闭操作 // ASyncClose represents asynchronous closure, i.e., the closure operation is performed in a new goroutine ASyncClose CloseType = iota // SyncClose 表示同步关闭,即在不同的 TerminateSignal 中同步执行关闭操作, eg: t1.Close() then t2.Close() then t3.Close() // 在每个 TerminateSignal 中,是异步执行的 // SyncClose represents synchronous closure, i.e., the closure operation is performed synchronously in different TerminateSignal, eg: t1.Close() then t2.Close() then t3.Close() // In each TerminateSignal, it is asynchronous SyncClose // ForceSyncClose 表示强制同步关闭,即在不同的 TerminateSignal 中同步执行关闭操作, eg: t1.Close() then t2.Close() then t3.Close() // 在每个 TerminateSignal 中,是完全同步执行的 // ForceSyncClose represents forced synchronous closure, i.e., the closure operation is performed synchronously in different TerminateSignal, eg: t1.Close() then t2.Close() then t3.Close() // In each TerminateSignal, it is completely synchronous ForceSyncClose )
定义了三种关闭类型:异步关闭、同步关闭和强制同步关闭 Three types of closure are defined: asynchronous closure, synchronous closure, and forced synchronous closure
type TerminateSignal ¶
type TerminateSignal struct {
// contains filtered or unexported fields
}
TerminateSignal 结构体包含了一个 context,一个取消函数,一个等待组,一个函数切片和一个 sync.Once 实例 The TerminateSignal struct contains a context, a cancel function, a wait group, a function slice, and a sync.Once instance
func NewTerminateSignal ¶
func NewTerminateSignal() *TerminateSignal
NewTerminateSignal 创建一个带有超时的 TerminateSignal 实例 NewTerminateSignal creates a TerminateSignal instance with a timeout
func NewTerminateSignalWithContext ¶
func NewTerminateSignalWithContext(ctx context.Context) *TerminateSignal
NewTerminateSignalWithContext 创建一个带有上下文和超时的 TerminateSignal 实例 NewTerminateSignalWithContext creates a TerminateSignal instance with context and timeout
func (*TerminateSignal) Close ¶
func (s *TerminateSignal) Close(wg *sync.WaitGroup)
Close 方法异步关闭 TerminateSignal 实例 The Close method asynchronously closes the TerminateSignal instance
func (*TerminateSignal) GetStopContext ¶ added in v0.1.1
func (s *TerminateSignal) GetStopContext() context.Context
GetStopContext 获取停止信号的 Context GetStopContext gets the Context of the stop signal
func (*TerminateSignal) RegisterCancelHandles ¶ added in v0.1.5
func (s *TerminateSignal) RegisterCancelHandles(handles ...func())
RegisterCancelHandles 注册需要取消的处理函数 RegisterCancelHandles registers the handle functions to be canceled
func (*TerminateSignal) SyncClose ¶ added in v0.1.3
func (s *TerminateSignal) SyncClose(wg *sync.WaitGroup)
SyncClose 方法同步关闭 TerminateSignal 实例 The SyncClose method synchronously closes the TerminateSignal instance