Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var WithLimiterDynamicPeriod = func(dynamicPeriod time.Duration) func(*limiter) {
return func(l *limiter) {
l.dynamicPeriod = dynamicPeriod
}
}
var WithLimiterStatsTriggerFunc = func(triggerFunc func() <-chan time.Time) func(*limiter) {
return func(l *limiter) {
l.stats.triggerFunc = triggerFunc
}
}
var WithLimiterTags = func(tags stats.Tags) func(*limiter) {
return func(l *limiter) {
l.tags = tags
}
}
Functions ¶
This section is empty.
Types ¶
type EagerGroup ¶ added in v0.27.0
type EagerGroup struct {
// contains filtered or unexported fields
}
A EagerGroup is a collection of goroutines working on subtasks that are part of the same overall task.
Use NewEagerGroup to create a new group.
func NewEagerGroup ¶ added in v0.27.0
NewEagerGroup returns a new eager group and an associated Context derived from ctx.
The derived Context is canceled the first time a function passed to Go returns a non-nil error or the first time Wait returns, whichever occurs first.
limit < 1 means no limit on the number of active goroutines.
func (*EagerGroup) Go ¶ added in v0.27.0
func (g *EagerGroup) Go(f func() error)
Go calls the given function in a new goroutine. It blocks until the new goroutine can be added without the number of active goroutines in the group exceeding the configured limit.
The first call to return a non-nil error cancels the group's context. The error will be returned by Wait.
If the group was created by calling NewEagerGroup with limit < 1, there is no limit on the number of active goroutines.
If the group's context is canceled, routines that have not executed yet due to the limit won't be executed. Additionally, there is a best effort not to execute `f()` once the context is canceled and that happens whether or not a limit has been specified.
func (*EagerGroup) Wait ¶ added in v0.27.0
func (g *EagerGroup) Wait() error
Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them.
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
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.