sync

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 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

构造一个Closer

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 SyncValue added in v0.2.1

type SyncValue[T any] chan T

数据同步

func NewSyncValue added in v0.2.1

func NewSyncValue[T any]() SyncValue[T]

func (SyncValue[T]) Close added in v0.2.1

func (s SyncValue[T]) Close() (e error)

func (SyncValue[T]) Recv added in v0.2.1

func (s SyncValue[T]) Recv() <-chan T

func (SyncValue[T]) Send added in v0.2.1

func (s SyncValue[T]) Send() chan<- T

func (SyncValue[T]) TimedRecv added in v0.2.1

func (s SyncValue[T]) TimedRecv(dur time.Duration) (T, bool)

func (SyncValue[T]) TimedSend added in v0.2.1

func (s SyncValue[T]) TimedSend(v T, dur time.Duration) bool

func (SyncValue[T]) TryRecv added in v0.2.1

func (s SyncValue[T]) TryRecv() (T, bool)

func (SyncValue[T]) TrySend added in v0.2.1

func (s SyncValue[T]) TrySend(v T) bool

func (SyncValue[T]) WaitRecv added in v0.2.1

func (s SyncValue[T]) WaitRecv() T

func (SyncValue[T]) WaitSend added in v0.2.1

func (s SyncValue[T]) WaitSend(v T)

type Task added in v0.1.6

type Task func(context.Context)

type WaitPool added in v0.2.0

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

func NewWaitPool added in v0.2.0

func NewWaitPool(ctx context.Context, maxGoroutine int) *WaitPool

func (*WaitPool) Err added in v0.2.1

func (p *WaitPool) Err() error

func (*WaitPool) Go added in v0.2.0

func (p *WaitPool) Go(f waitPoolTask) error

func (*WaitPool) Wait added in v0.2.0

func (p *WaitPool) Wait() error

调用Wait()后,等待任务执行完毕,不能再开启任务,退出goroutine

type Waiter added in v0.2.1

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

同步执行

func NewWaiter added in v0.2.1

func NewWaiter() *Waiter

func (*Waiter) Close added in v0.2.1

func (w *Waiter) Close() (e error)

func (*Waiter) Recv added in v0.2.1

func (w *Waiter) Recv() <-chan struct{}

func (*Waiter) Send added in v0.2.1

func (w *Waiter) Send() chan<- struct{}

func (*Waiter) TimedRecv added in v0.2.1

func (w *Waiter) TimedRecv(dur time.Duration) bool

成功收到信号返回true,超时返回false

func (*Waiter) TimedSend added in v0.2.1

func (w *Waiter) TimedSend(dur time.Duration) bool

成功发送信号返回true,超时返回false

func (*Waiter) TryRecv added in v0.2.1

func (w *Waiter) TryRecv() bool

尝试读

func (*Waiter) TrySend added in v0.2.1

func (w *Waiter) TrySend() bool

尝试写

func (*Waiter) WaitRecv added in v0.2.1

func (w *Waiter) WaitRecv()

func (*Waiter) WaitSend added in v0.2.1

func (w *Waiter) WaitSend()

Jump to

Keyboard shortcuts

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