Documentation ¶
Overview ¶
Package rate contains rate limiting strategies for asynq.Handler(s).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore is a distributed counting semaphore which can be used to set maxTokens across multiple asynq servers.
func NewSemaphore ¶
func NewSemaphore(rco asynq.RedisConnOpt, scope string, maxTokens int) *Semaphore
NewSemaphore creates a counting Semaphore for the given scope with the given number of tokens.
func (*Semaphore) Acquire ¶
Acquire attempts to acquire a token from the semaphore. - Returns (true, nil), iff semaphore key exists and current value is less than maxTokens - Returns (false, nil) when token cannot be acquired - Returns (false, error) otherwise
The context.Context passed to Acquire must have a deadline set, this ensures that token is released if the job goroutine crashes and does not call Release.