Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyLimit ¶
KeyLimit defines a concurrency limit for a set of keys.
All keys of one set share the same limit. Keys of different sets have separate limits.
Sets must not overlap.
type Limiter ¶
type Limiter interface {
// Acquire attempts to reserve a slot without blocking.
//
// Returns a release function and true if successful. The function must be
// called to release the limiter. The function must be called exactly once.
// Calling the function more that once will cause incorrect behavior of the
// limiter.
//
// Returns nil and false if fails.
//
// If the key was not defined in the limiter, no limit is applied.
Acquire(key string) (ReleaseFunc, bool)
// AcquireFirstOf attempts to reserve a slot without blocking.
// Slot will be reserved by the first found key. Order in the provided keys
// is important.
//
// Returns a release function and true if successful. The function must be
// called to release the limiter. The function must be called exactly once.
// Calling the function more that once will cause incorrect behavior of the
// limiter.
//
// Returns nil and false if fails.
//
// If the keys was not defined in the limiter, no limit is applied.
AcquireFirstOf(keys ...string) (ReleaseFunc, bool)
}
type ReleaseFunc ¶
type ReleaseFunc func()
type SemaphoreLimiter ¶
type SemaphoreLimiter struct {
// contains filtered or unexported fields
}
func NewSemaphoreLimiter ¶
func NewSemaphoreLimiter(limits []KeyLimit) (*SemaphoreLimiter, error)
func (*SemaphoreLimiter) Acquire ¶
func (lr *SemaphoreLimiter) Acquire(key string) (ReleaseFunc, bool)
func (*SemaphoreLimiter) AcquireFirstOf ¶
func (lr *SemaphoreLimiter) AcquireFirstOf(keys ...string) (ReleaseFunc, bool)
Click to show internal directories.
Click to hide internal directories.