sync

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MulanPSL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LockGuard

func LockGuard(l sync.Locker, chunk func())

func RLockGuard

func RLockGuard(l RLocker, chunk func())

Types

type Closer added in v0.1.6

type Closer interface {
	io.Closer
	IsClosed() bool
	Done() <-chan struct{}
	Wait()
}

stopper与closer的区别在于,Close()返回error,而Stop()返回是否执行了停止

func NewClosed added in v0.1.6

func NewClosed() Closer

func NewCloser added in v0.1.6

func NewCloser() Closer

构造一个Stopper

type GoPool added in v0.1.6

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

func NewGoPool added in v0.1.6

func NewGoPool(opts ...GoPoolOption) *GoPool

func (*GoPool) Close added in v0.1.6

func (p *GoPool) Close()

func (*GoPool) Go added in v0.1.6

func (p *GoPool) Go(f Task) (e error)

执行一个任务,如果没有空闲goroutine则等待

func (*GoPool) IsWorking added in v0.1.6

func (p *GoPool) IsWorking() bool

判断是否存在任务正在执行

func (*GoPool) MustGo added in v0.1.6

func (p *GoPool) MustGo(f Task) (e error)

执行一个任务,如果没有空闲goroutine则直接执行

func (*GoPool) TryGo added in v0.1.6

func (p *GoPool) TryGo(f Task) (ok bool)

尝试执行一个任务,如果没有空闲goroutine则返回false

type GoPoolOption added in v0.1.6

type GoPoolOption func(*GoPool)

func GoLifetime added in v0.1.6

func GoLifetime(n time.Duration) GoPoolOption

goroutine最低保留时间

func MaxGoroutine added in v0.1.6

func MaxGoroutine(n int) GoPoolOption

最多开启goroutine个数

func MinGoroutine added in v0.1.6

func MinGoroutine(n int) GoPoolOption

保留最少goroutine个数

type GoPoolStatus added in v0.1.6

type GoPoolStatus = int32

type RLocker

type RLocker interface {
	RLock()
	RUnlock()
}

type Task added in v0.1.6

type Task func(context.Context)

Jump to

Keyboard shortcuts

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