sync

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExceedLimit error = errors.New("exceed limit")
)

Functions

func Recovery added in v0.1.9

func Recovery(hr ...Handler)

func SafeGo

func SafeGo(f func(), panicCallBack Handler)

Types

type ConGroup

type ConGroup interface {
	NewGroup(ctx context.Context, opts ...GroupOption) Group
}

func NewConGroup

func NewConGroup(maxConcurrency int) ConGroup

type GoFunc

type GoFunc func(context.Context) error

type Group

type Group interface {
	// cancel all execution unit
	Cancel()

	// Wait wait all execution unit to quit
	Wait() error

	// Go start an execution unit, would be blocked when exceed limitation
	Go(GoFunc)

	// TryGo if exceeds limitation, return ErrExceedLimit
	TryGo(GoFunc) error

	//
	Errors() []error

	//
	WrapError() error
}

Group execute group

func NewGroup

func NewGroup(ctx context.Context, opts ...GroupOption) Group

type GroupOption

type GroupOption interface {
	// contains filtered or unexported methods
}

func WithCancelIfError

func WithCancelIfError(enable bool) GroupOption

WithCancelIfError cancel all executions when one return error

type Handler added in v0.1.9

type Handler func(interface{})

type Sema

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

func NewSema

func NewSema(count int) *Sema

func (*Sema) Signal

func (s *Sema) Signal()

func (*Sema) Wait

func (s *Sema) Wait()

func (*Sema) WaitChan

func (s *Sema) WaitChan() <-chan struct{}

type WaitChannel

type WaitChannel <-chan struct{}

func NewWaitChannel

func NewWaitChannel() WaitChannel

type WaitCloser

type WaitCloser interface {
	Close(error) bool
	IsClosed() bool
	Error() error

	Context() context.Context
	Done() WaitChannel

	// sleep until expired or closed
	Sleep(time.Duration)

	// wait group interface
	WgAdd(int)
	WgDone()
	WgWait()
}

WaitCloser is convenient for concurrent programming used to control lifetime of concurrent executions.

func NewWaitCloser

func NewWaitCloser(stopFun func(error)) WaitCloser

func NewWaitCloserFromContext

func NewWaitCloserFromContext(pctx context.Context, stopFun func(error)) WaitCloser

func NewWaitCloserFromParent

func NewWaitCloserFromParent(p WaitCloser, stopFun func(error)) WaitCloser

type WaitNotifier

type WaitNotifier chan struct{}

func NewWaitNotifier

func NewWaitNotifier() WaitNotifier

Jump to

Keyboard shortcuts

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