Concurrency Limiters#
This module contains the default concurrency limiter implementation in arc
along with several helper functions to create common variants of it.
Note
Concurrency limiters are not regular hooks and need a special decorator to be set. You can only have 1 concurrency limiter per command.
CommandConcurrencyLimiter
#
Bases: ConcurrencyLimiter[Context[ClientT]]
, ConcurrencyLimiterProto[ClientT]
A concurrency limiter specialized for use with arc
commands.
This limiter only accepts arc.context.Context
instances as keys.
For a generic implementation that works with any key type,
see ConcurrencyLimiter
.
PARAMETER | DESCRIPTION |
---|---|
capacity |
The maximum amount of concurrently running command instances.
TYPE:
|
get_key_with |
A callable that returns a key for the concurrency limiter bucket. |
See Also
__call__
#
acquire
async
#
Acquire a concurrency slot for an item.
This will block until a slot is available.
ConcurrencyLimiter
#
Bases: Generic[KeyT]
A general purpose concurrency limiter. Accepts a key extraction function and allocates buckets for each unique key.
Example:
limiter = arc.utils.ConcurrencyLimiter[int](
capacity=5,
get_key_with=lambda x: str(x),
)
async with limiter(69):
print("69 is now being processed")
Note
For use with commands, see CommandConcurrencyLimiter
.
PARAMETER | DESCRIPTION |
---|---|
capacity |
The maximum amount of concurrently running requests.
TYPE:
|
get_key_with |
A callable that returns a key for the concurrency limiter bucket. |
See Also
__call__
#
acquire
async
#
Acquire a concurrency slot for an item.
This will block until a slot is available.
channel_concurrency
#
channel_concurrency(limit: int) -> CommandConcurrencyLimiter[Any]
Limit a command to a certain amount of concurrent instances per channel.
PARAMETER | DESCRIPTION |
---|---|
limit |
The maximum amount of concurrently running command instances.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CommandConcurrencyLimiter[Any]
|
A concurrency limiter for use with a command. |
custom_concurrency
#
custom_concurrency(
limit: int, get_key_with: Callable[[Context[ClientT]], str]
) -> CommandConcurrencyLimiter[Any]
Limit a command to a certain amount of concurrent instances per custom key.
PARAMETER | DESCRIPTION |
---|---|
limit |
The maximum amount of concurrently running command instances.
TYPE:
|
get_key_with |
A callable that returns a key for the concurrency limiter bucket. |
RETURNS | DESCRIPTION |
---|---|
CommandConcurrencyLimiter[Any]
|
A concurrency limiter for use with a command. |
global_concurrency
#
global_concurrency(limit: int) -> CommandConcurrencyLimiter[Any]
Limit a command to a certain amount of concurrent instances globally.
PARAMETER | DESCRIPTION |
---|---|
limit |
The maximum amount of concurrently running command instances.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CommandConcurrencyLimiter[Any]
|
A concurrency limiter for use with a command. |
guild_concurrency
#
guild_concurrency(limit: int) -> CommandConcurrencyLimiter[Any]
Limit a command to a certain amount of concurrent instances per guild.
PARAMETER | DESCRIPTION |
---|---|
limit |
The maximum amount of concurrently running command instances.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CommandConcurrencyLimiter[Any]
|
A concurrency limiter for use with a command. |
member_concurrency
#
member_concurrency(limit: int) -> CommandConcurrencyLimiter[Any]
Limit a command to a certain amount of concurrent instances per member.
PARAMETER | DESCRIPTION |
---|---|
limit |
The maximum amount of concurrently running command instances.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CommandConcurrencyLimiter[Any]
|
A concurrency limiter for use with a command. |
user_concurrency
#
user_concurrency(limit: int) -> CommandConcurrencyLimiter[Any]
Limit a command to a certain amount of concurrent instances per user.
PARAMETER | DESCRIPTION |
---|---|
limit |
The maximum amount of concurrently running command instances.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CommandConcurrencyLimiter[Any]
|
A concurrency limiter for use with a command. |