scc

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: Apache-2.0 Imports: 7 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = New(nil)
View Source
var ErrorTimeout = errors.New("timeout")

Functions

func Add

func Add(delta int)

func CGO

func CGO(f handle)

CGO 带有取消通道的协程

func Cancel

func Cancel() bool

Cancel ,callback:成功调用Close后 cancel之前调用

func Done

func Done()

func GO

func GO(f func())

GO 普通的GO

func SGO

func SGO(f handle)

SGO 使用recover保护主进程,使用一个handle进行错误信息处理

func Stopped

func Stopped() bool

Stopped 判断是否已经关闭

func Timeout

func Timeout(d time.Duration, fn func() error) error

func Trigger added in v1.2.0

func Trigger(handle func())

Trigger 服务器关闭时触发

func Try

func Try(f handle)

func Wait

func Wait(timeout time.Duration) (err error)

func WithCancel added in v1.1.0

func WithCancel() (context.Context, context.CancelFunc)

func WithTimeout added in v1.1.0

func WithTimeout(t time.Duration) (context.Context, context.CancelFunc)

func WithValue added in v1.2.0

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

Types

type Daemon

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

func NewDaemon added in v1.1.0

func NewDaemon(scc *SCC) *Daemon

func (*Daemon) Start added in v1.1.0

func (d *Daemon) Start(f handle) *Worker

Start 守护协程,协程异常退出时会自动重启协程,一般使用在随主进程启动的固定协程

type SCC

type SCC struct {
	sync.WaitGroup

	Catch   func(error) //异常捕获,默认控制台打印
	Context context.Context
	// contains filtered or unexported fields
}

SCC 协程控制器

func New

func New(ctx context.Context) *SCC

func (*SCC) CGO

func (s *SCC) CGO(f handle)

CGO 带有取消通道的协程

func (*SCC) Cancel

func (s *SCC) Cancel() bool

Cancel 关闭所有协程

func (*SCC) Deadline added in v1.1.0

func (s *SCC) Deadline() (deadline time.Time, ok bool)

func (*SCC) GO

func (s *SCC) GO(f func())

GO 普通的GO

func (*SCC) SGO

func (s *SCC) SGO(f handle)

SGO 使用recover保护主进程

func (*SCC) Stopped

func (s *SCC) Stopped() bool

Stopped 判断是否已经关闭

func (*SCC) Timeout added in v0.0.5

func (s *SCC) Timeout(d time.Duration, fn func() error) error

func (*SCC) Trigger added in v1.2.0

func (s *SCC) Trigger(f func())

func (*SCC) Try

func (s *SCC) Try(f handle)

func (*SCC) Wait

func (s *SCC) Wait(timeout time.Duration) (err error)

Wait 阻塞模式等待所有协程结束 一般只在启动后主进程中使用 请不要在SCC创建的协程中使用,否者会无限等待

func (*SCC) WithCancel added in v1.1.0

func (s *SCC) WithCancel() (context.Context, context.CancelFunc)

func (*SCC) WithTimeout added in v1.1.0

func (s *SCC) WithTimeout(t time.Duration) (context.Context, context.CancelFunc)

func (*SCC) WithValue added in v1.2.0

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

type Worker added in v1.1.0

type Worker struct {
	Handle handle
	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

func (*Worker) Stop added in v1.1.0

func (w *Worker) Stop()

Jump to

Keyboard shortcuts

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