sync

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: AGPL-3.0 Imports: 8 Imported by: 10

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 Limiter

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. End can be called multiple times without any side effects
	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. End can be called multiple times without any side effects
	BeginWithPriority(key string, priority LimiterPriorityValue) (end func())
}

Limiter limits the number of concurrent operations that can be performed

func NewLimiter

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

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

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

func NewPartitionLocker() *PartitionLocker

NewPartitionLocker returns a new PartitionLocker.

func (*PartitionLocker) Lock

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

func (p *PartitionLocker) Unlock(id string)

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

type PartitionRWLocker

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

func NewPartitionRWLocker() *PartitionRWLocker

NewPartitionRWLocker returns a new PartitionRWLocker.

func (*PartitionRWLocker) Lock

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

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

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

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

RWMutexFor returns a new RWMutex scoped to the given id.

func (*PartitionRWLocker) Unlock

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

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

RWMutex is a read-write lock

func (*RWMutex) Lock

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

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

func (m *RWMutex) RUnlock()

func (*RWMutex) Unlock

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