halo

package
v0.1.1-rc06 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGracefulShutdownTimeout = errors.New("graceful shutdown timeout")
)

Functions

func AddShutdownCallback

func AddShutdownCallback(f func())

AddShutdownCallback 注册一个进程停止时的回调函数

func GetGoID

func GetGoID() int64

GetGoID 返回协程ID

func GracefulRun

func GracefulRun(f func(ctx context.Context))

GracefulRun 启动一个优雅停机 goroutine

func GracefulRunSync

func GracefulRunSync(f func(ctx context.Context))

GracefulRunSync 同步执行一个优雅停机函数

func SafeGo

func SafeGo(f func())

SafeGo 启动一个 goroutine,并捕获 panic

func SetInterval

func SetInterval(fn func(), d time.Duration)

SetInterval 定时执行

func Wait

func Wait(timeout time.Duration) error

Wait 等待所有 goroutine 退出 当收到 kill 信号时,最多等待 timeout 时长,超时则返回 ErrGracefulShutdownTimeout

Types

type Context

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

func NewContext

func NewContext(ctx context.Context) *Context

func WithValue

func WithValue(parent context.Context, key, val any) *Context

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) Set

func (c *Context) Set(key, val any)

func (*Context) Value

func (c *Context) Value(key any) any

type Singleton

type Singleton[T any] struct {
	// contains filtered or unexported fields
}

Singleton 是一个泛型的结构体,支持任意类型的单例模式

func NewSingleton

func NewSingleton[T any](factory func() *T) *Singleton[T]

func (*Singleton[T]) Get

func (s *Singleton[T]) Get() *T

Get 提供一个获取单例对象的通用方法

Jump to

Keyboard shortcuts

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