Documentation ¶
Overview ¶
Package limit provides primitives to limit concurrency.
Note that this is not to be confused with rate-limiting. With concurrency limiting (which is what this package does), you are limiting the number of operations that can be running at any given point in time. With rate limiting, you are limiting the number of operations that can be fired within a given time window.
For instance, even if you limit concurrency to 1, you can still N requests per second if each request takes 1/N second to complete.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrencyLimiter ¶
type ConcurrencyLimiter interface { // Acquire acquires the right to proceed. It blocks if the concurrency // limit has been reached. Acquire() // Release signals that an operation has completed. Release() // Wait blocks until all operations that have called Acquire thus far // are completed. Wait() }
ConcurrencyLimiter limits the number of concurrent operations If the ConcurrencyLimiter is initialized with a concurrency of 0, then all of the following functions will be no-ops, meaning that an arbitrary concurrency is allowed.
func New ¶
func New(concurrency int) ConcurrencyLimiter
New returns a new ConcurrencyLimiter with the given limit