egroup

package
v0.0.0-...-b628505 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetSignal

func SetSignal(handler func(*LifeAdmin, os.Signal), signals ...os.Signal) options.Option

SetSignal 设置信号集合,和处理信号的函数

func SetStartTimeout

func SetStartTimeout(d time.Duration) options.Option

SetStartTimeout 设置启动超时时间

func SetStopTimeout

func SetStopTimeout(d time.Duration) options.Option

SetStopTimeout 设置停止超时时间

Types

type Group

type Group struct {
	sync.Once
	// contains filtered or unexported fields
}

func WithContext

func WithContext(ctx context.Context) *Group

WithContext 实例化方法

func WithContextGroup

func WithContextGroup(ctx context.Context, group goroutine.GGroup) *Group

func (*Group) Go

func (g *Group) Go(f func() error)

Go 异步调用

func (*Group) Wait

func (g *Group) Wait() error

Wait 等待

type LifeAdmin

type LifeAdmin struct {
	// contains filtered or unexported fields
}

LifeAdmin 生命周期管理

func NewLifeAdmin

func NewLifeAdmin(opts ...options.Option) *LifeAdmin

NewLifeAdmin 实例化方法

Example
// 默认配置
// admin = NewLifeAdmin()

// 可供选择配置选项

// 设置启动超时时间
// <=0 不启动超时时间,注意要在shutdown处理关闭通知
// SetStartTimeout(time.Second)

//  设置关闭超时时间
//	<=0 不启动超时时间
// SetStopTimeout(time.Second)

// 设置信号集合,和处理信号的函数
//SetSignal(func(lifeAdmin *LifeAdmin, signal os.Signal) {
//	return
//}, signal...)

admin = NewLifeAdmin(SetStartTimeout(time.Second), SetStopTimeout(time.Second), SetSignal(func(a *LifeAdmin, signal os.Signal) {
	switch signal {
	case syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT:
		a.shutdown()
	default:
	}
}))
Output:

func (*LifeAdmin) Add

func (l *LifeAdmin) Add(member Member)

Add 添加成员表(通过内部 Member 对象添加)

Example
// 通过struct添加
admin.Add(Member{
	Start:    mockStart(),
	Shutdown: mockShutdown(),
})
Output:

func (*LifeAdmin) AddMember

func (l *LifeAdmin) AddMember(la LifeAdminer)

AddMember 添加程序表(通过外部接口 LifeAdminer 添加)

Example
// 根据接口适配添加
admin.AddMember(&mockLifeAdminer{})
Output:

func (*LifeAdmin) Shutdown

func (l *LifeAdmin) Shutdown()

Shutdown 停止服务

func (*LifeAdmin) Start

func (l *LifeAdmin) Start() error

Start 启动

Example
defer admin.Shutdown()
if err := admin.Start(); err != nil {
	// 处理错误
	// 正常启动会hold主
}
Output:

type LifeAdminer

type LifeAdminer interface {
	Start(ctx context.Context) error
	Shutdown(ctx context.Context) error
}

LifeAdminer 生命周期管理接口

type Member

type Member struct {
	Start    func(ctx context.Context) error
	Shutdown func(ctx context.Context) error
}

Member 成员

Jump to

Keyboard shortcuts

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