sync

package
v1.9.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WithLimiterDynamicPeriod = func(dynamicPeriod time.Duration) func(*limiter) {
	return func(l *limiter) {
		l.dynamicPeriod = dynamicPeriod
	}
}
View Source
var WithLimiterStatsTriggerFunc = func(triggerFunc func() <-chan time.Time) func(*limiter) {
	return func(l *limiter) {
		l.stats.triggerFunc = triggerFunc
	}
}
View Source
var WithLimiterTags = func(tags stats.Tags) func(*limiter) {
	return func(l *limiter) {
		l.tags = tags
	}
}

Functions

This section is empty.

Types

type First

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

func (*First) First

func (f *First) First() bool

type Limiter added in v1.6.0

type Limiter interface {
	// Do executes the function f, but only if there are available slots.
	// Otherwise blocks until a slot becomes available
	Do(key string, f func())

	// DoWithPriority executes the function f, but only if there are available slots.
	// Otherwise blocks until a slot becomes available, respecting the priority
	DoWithPriority(key string, priority LimiterPriorityValue, f func())

	// Begin starts a new operation, blocking until a slot becomes available.
	// Caller is expected to call the returned function to end the operation, otherwise
	// the slot will be reserved indefinitely
	Begin(key string) (end func())

	// BeginWithPriority starts a new operation, blocking until a slot becomes available, respecting the priority.
	// Caller is expected to call the returned function to end the operation, otherwise
	// the slot will be reserved indefinitely
	BeginWithPriority(key string, priority LimiterPriorityValue) (end func())
}

Limiter limits the number of concurrent operations that can be performed

func NewLimiter added in v1.6.0

func NewLimiter(ctx context.Context, wg *sync.WaitGroup, name string, limit int, statsf stats.Stats, opts ...func(*limiter)) Limiter

NewLimiter creates a new limiter

type LimiterPriorityValue added in v1.6.0

type LimiterPriorityValue int

LimiterPriorityValue defines the priority values supported by Limiter. Greater priority value means higher priority

const (

	// LimiterPriorityValueLow Priority....
	LimiterPriorityValueLow LimiterPriorityValue
	// LimiterPriorityValueMedium Priority....
	LimiterPriorityValueMedium
	// LimiterPriorityValueMediumHigh Priority....
	LimiterPriorityValueMediumHigh
	// LimiterPriorityValueHigh Priority.....
	LimiterPriorityValueHigh
)

type PartitionLocker added in v1.6.0

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

PartitionLocker is a lock that can be used to lock different partitions at the same time.

func NewPartitionLocker added in v1.6.0

func NewPartitionLocker() *PartitionLocker

NewPartitionLocker returns a new PartitionLocker.

func (*PartitionLocker) Lock added in v1.6.0

func (p *PartitionLocker) Lock(id string)

Lock locks the lock. If the lock is locked, it waits until the lock is unlocked.

func (*PartitionLocker) Unlock added in v1.6.0

func (p *PartitionLocker) Unlock(id string)

Unlock unlocks the lock. If the lock is not locked, it panics.

type PartitionRWLocker added in v1.6.0

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

PartitionRWLocker is a read-write lock that can be used to lock different partitions at the same time.

func NewPartitionRWLocker added in v1.6.0

func NewPartitionRWLocker() *PartitionRWLocker

NewPartitionRWLocker returns a new PartitionRWLocker.

func (*PartitionRWLocker) Lock added in v1.6.0

func (p *PartitionRWLocker) Lock(id string)

Lock locks the lock for writing. If the lock is locked for reading or writing, it waits until the lock is unlocked.

func (*PartitionRWLocker) RLock added in v1.6.0

func (p *PartitionRWLocker) RLock(id string)

RLock locks the lock for reading. If the lock is locked for writing, it waits until the lock is unlocked.

func (*PartitionRWLocker) RUnlock added in v1.6.0

func (p *PartitionRWLocker) RUnlock(id string)

RUnlock unlocks the lock for reading. If the lock is locked for writing or not locked for reading, it panics.

func (*PartitionRWLocker) RWMutexFor added in v1.6.0

func (p *PartitionRWLocker) RWMutexFor(id string) *RWMutex

RWMutexFor returns a new RWMutex scoped to the given id.

func (*PartitionRWLocker) Unlock added in v1.6.0

func (p *PartitionRWLocker) Unlock(id string)

Unlock unlocks the lock for writing. If the lock is locked for reading or not locked for writing, it panics.

type RWMutex added in v1.6.0

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

RWMutex is a read-write lock

func (*RWMutex) Lock added in v1.6.0

func (m *RWMutex) Lock()

Lock locks the lock for writing. If the lock is locked for reading or writing, it waits until the lock is unlocked.

func (*RWMutex) RLock added in v1.6.0

func (m *RWMutex) RLock()

RLock locks the lock for reading. If the lock is locked for writing, it waits until the lock is unlocked.

func (*RWMutex) RUnlock added in v1.6.0

func (m *RWMutex) RUnlock()

func (*RWMutex) Unlock added in v1.6.0

func (m *RWMutex) Unlock()

Unlock unlocks the lock for writing. If the lock is locked for reading or not locked for writing, it panics.

Jump to

Keyboard shortcuts

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