sync

package
v0.0.0-...-61344ea Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultStackSize = 64 << 10 // 64KB

DefaultStackSize is the default size for stack traces

Variables

View Source
var ErrCountdownTimerExpired = errors.New("countdown timer expired")
View Source
var GroupStopping = errors.New("ErrGroup is stopping") // Stoppable is stopping signal

Functions

func CatchErr

func CatchErr(p interface{}) error

CatchErr creates an error with stack trace from a recovered panic. It captures the current stack trace and formats it as part of the error message.

func CatchErrWithSize

func CatchErrWithSize(p interface{}, stackSize int) error

CatchErrWithSize creates an error with a stack trace of the specified size from a recovered panic. stackSize: the maximum size of the stack trace to capture

func GoSafe

func GoSafe(msg string, fn func() error)

GoSafe executes a function in a separate goroutine with panic recovery. It logs any errors that occur during execution. msg: descriptive message for logging fn: function to execute safely

func RoutineId

func RoutineId() uint64

RoutineId returns the current goroutine ID. Warning: Only for debug purposes, never use it in production. The implementation is based on parsing the runtime stack.

func RunSafe

func RunSafe(fn func() error) (err error)

RunSafe executes a function with panic recovery. Returns the error from the function or a wrapped error if a panic occurred.

Types

type CountdownStopper

type CountdownStopper interface {
	ExpiryTime() time.Time
	SetExpiryTime(time.Time)
	Reset()
}

CountdownStopper the interface for countdown stoppers

func NewCountdownStopper

func NewCountdownStopper() CountdownStopper

NewCountdownStopper creates a new countdown stopper

type StopTriggerable

type StopTriggerable interface {
	// TriggerStop trigger stop
	TriggerStop()
	// StopTriggered listen stop is triggered
	StopTriggered() <-chan struct{}
}

StopTriggerable trigger stop interface

type Stoppable

type Stoppable interface {
	WaitStoppable
	StopTriggerable

	// DoStop execute stop
	DoStop(f func())
	// Stopping listen stop is started
	Stopping() <-chan struct{}
	// IsStopping check stop is started
	IsStopping() bool
}

Stoppable lifecycle stop manager interface

type Stopper

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

Stopper implements Stoppable interface

func NewStopper

func NewStopper(stopTimeout time.Duration) *Stopper

func (*Stopper) DoStop

func (s *Stopper) DoStop(f func())

func (*Stopper) IsStopping

func (s *Stopper) IsStopping() bool

func (*Stopper) StopTriggered

func (s *Stopper) StopTriggered() <-chan struct{}

func (*Stopper) Stopping

func (s *Stopper) Stopping() <-chan struct{}

func (*Stopper) TriggerStop

func (s *Stopper) TriggerStop()

func (*Stopper) WaitStopped

func (s *Stopper) WaitStopped()

type WaitStoppable

type WaitStoppable interface {
	WaitStopped()
}

WaitStoppable wait stop completed

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳